tui

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: Apache-2.0 Imports: 13 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.

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 final summary for CI/simple mode (no colors)

func Run

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

Run starts the TUI application

Types

type ErrorInfo

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

ErrorInfo represents a failed run with details

type LogEntry

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

LogEntry represents a single log line

type LogInterceptor

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

LogInterceptor wraps an slog.Handler to intercept log messages and send them to the TUI. It also optionally writes logs to a file in verbose mode.

func NewLogInterceptor

func NewLogInterceptor(
	originalHandler slog.Handler, program *tea.Program, logFilePath string, suppressStderr bool,
) (*LogInterceptor, error)

NewLogInterceptor creates a log interceptor that sends logs to the TUI. If logFilePath is not empty, logs will also be written to that file. If suppressStderr is true, logs won't be sent to the original handler (useful for TUI mode).

func SetupLogger

func SetupLogger(logger *slog.Logger, program *tea.Program, logFilePath string, suppressStderr bool) (*LogInterceptor, error)

SetupLogger configures the provided logger to intercept logs and send them to the TUI. If logFilePath is not empty, logs will also be written to that file. If suppressStderr is true, logs won't be sent to stderr (useful for TUI mode). Returns the interceptor (to be closed when done) and an error if setup fails.

func (*LogInterceptor) Close

func (l *LogInterceptor) Close() error

Close closes the log file if one was opened.

func (*LogInterceptor) Enabled

func (l *LogInterceptor) Enabled(ctx context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level.

func (*LogInterceptor) FlushBuffer

func (l *LogInterceptor) FlushBuffer()

FlushBuffer writes all buffered logs to the original handler (stderr). Call this after the TUI exits to show any logs that occurred during execution.

func (*LogInterceptor) Handle

func (l *LogInterceptor) Handle(ctx context.Context, record slog.Record) error

Handle processes a log record by sending it to the TUI and optionally writing to file.

func (*LogInterceptor) WithAttrs

func (l *LogInterceptor) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new handler with additional attributes.

func (*LogInterceptor) WithGroup

func (l *LogInterceptor) WithGroup(name string) slog.Handler

WithGroup returns a new handler with an additional group.

type LogMsg

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

LogMsg is a bubbletea message sent when a log entry is intercepted.

type Model

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

Model represents the bubbletea application state

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) 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.

func (*Model) Init

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

Init initializes the bubbletea model

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 TUI

type Observer

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

Observer implements the ExecutionObserver interface to bridge engine callbacks to bubbletea messages. It converts engine events into bubbletea messages that can be processed by the TUI Model.

func NewObserver

func NewObserver(program *tea.Program) *Observer

NewObserver creates a new TUI observer that sends messages to the given bubbletea program.

func NewObserverWithModel

func NewObserverWithModel(model *Model) *Observer

NewObserverWithModel creates an observer that updates the model directly (headless mode)

func (*Observer) OnRunCompleted

func (o *Observer) OnRunCompleted(runID string, duration time.Duration, cost float64)

OnRunCompleted is called when a test run finishes successfully. This method is goroutine-safe and converts the callback to a bubbletea message.

func (*Observer) OnRunFailed

func (o *Observer) OnRunFailed(runID string, err error)

OnRunFailed is called when a test run fails with an error. This method is goroutine-safe and converts the callback to a bubbletea message.

func (*Observer) OnRunStarted

func (o *Observer) OnRunStarted(runID, scenario, provider, region string)

OnRunStarted is called when a test run begins execution. This method is goroutine-safe and converts the callback to a bubbletea message.

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
}

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 ShowSummaryMsg

type ShowSummaryMsg struct {
	Summary *Summary
}

ShowSummaryMsg is sent when execution completes and the final summary should be displayed

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
}

Summary represents the final execution summary displayed after all runs complete

Jump to

Keyboard shortcuts

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