tui

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 16 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 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 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(program *tea.Program) *EventAdapter

NewEventAdapter creates an adapter that forwards events to the TUI program.

func NewEventAdapterWithModel added in v1.1.4

func NewEventAdapterWithModel(model *Model) *EventAdapter

NewEventAdapterWithModel creates an adapter for headless mode.

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

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 struct {
	ID   string // Unique identifier for this tool call
	Name string // Name of the tool to invoke
	Args string // JSON-encoded tool arguments
}

MessageToolCall represents a tool call in a message (mirrors events.MessageToolCall).

type MessageToolResult added in v1.1.5

type MessageToolResult struct {
	ID        string // References the MessageToolCall.ID
	Name      string // Tool name that was executed
	Content   string // Result content
	Error     string // Error message if tool failed
	LatencyMs int64  // Tool execution latency
}

MessageToolResult represents a tool result in a message (mirrors events.MessageToolResult).

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

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