tui

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package tui implements the BubbleTea terminal UI for Cortex.

Following BubbleTea patterns: - Screen constants as iota - Single Model struct holds ALL state - Update() with type switch - Per-screen key handlers returning (tea.Model, tea.Cmd) - Vim keys (j/k) for navigation - PrevScreen for back navigation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Observations *sqlitestore.Store
	Sessions     *session.Store
	Search       *search.Store
	Graph        *graphstore.Store
	Scoring      *scoringstore.Store
	Entities     *entitystore.Store
	App          *app.App
	Config       *config.Config
	Version      string
}

Deps bundles all store dependencies for the TUI.

type Model

type Model struct {
	Version    string
	Screen     Screen
	PrevScreen Screen
	PrevCursor int
	Width      int
	Height     int
	Cursor     int
	Scroll     int

	// Update notification
	UpdateResult *update.Result

	// Error display
	ErrorMsg string

	// Dashboard
	Stats *combinedStats

	// Search
	SearchInput      textinput.Model
	SearchQuery      string
	SearchResults    []*domain.SearchResult
	SearchHistory    []string
	SearchHistoryIdx int

	// Recent observations
	RecentObservations []*domain.Observation

	// Observation detail (enriched with Cortex data)
	SelectedObservation *domain.Observation
	DetailScore         *domain.ImportanceScore
	DetailEntities      []*domain.EntityLink
	DetailEdges         []*domain.Edge
	DetailViewport      viewport.Model
	DetailLoading       bool

	// Timeline
	TimelineFocus  *domain.Observation
	TimelineBefore []*domain.Observation
	TimelineAfter  []*domain.Observation

	// Sessions
	Sessions            []*session.SessionStats
	SelectedSessionIdx  int
	SessionObservations []*domain.Observation
	SessionDetailScroll int

	// Graph (Cortex-exclusive)
	GraphObservations []*domain.Observation
	GraphEdges        []*domain.Edge
	GraphRootID       int64

	// List filtering
	FilterProject string // active project filter ("" = all)
	FilterActive  bool   // whether filter is shown

	// Vim multi-key sequences
	PendingKey string // for multi-key sequences like "gg"

	// Archive (Cortex-exclusive)
	ArchivedObservations []*domain.Observation

	// Health (Cortex-exclusive)
	HealthStale      []*domain.Observation
	HealthOrphans    []*domain.Observation
	HealthEdgeCount  int
	HealthObsCount   int
	HealthCandidates []healthCandidate
	HealthSection    int // 0=stale, 1=orphans, 2=candidates
	HealthExpanded   bool

	// Setup
	SetupAgents           []setup.Agent
	SetupResult           *setup.Result
	SetupInstalling       bool
	SetupInstallingName   string
	SetupDone             bool
	SetupError            string
	SetupAllowlistPrompt  bool
	SetupAllowlistApplied bool
	SetupAllowlistError   string
	SetupSpinner          spinner.Model

	// Embedding config
	EmbCfgDirty          bool
	EmbCfgProvider       int             // 0=none, 1=ollama, 2=openai
	EmbCfgModel          textinput.Model // model name input
	EmbCfgVector         bool            // vector search toggle
	EmbCfgAutoStart      bool            // auto-start Ollama toggle
	EmbCfgFocusField     int             // focused field (0=provider, 1=model, 2=vector, 3=autostart, 4=save)
	EmbCfgSaving         bool
	EmbCfgSaved          bool
	EmbCfgError          string
	EmbCfgOllamaRunning  bool
	EmbCfgOllamaHasModel bool
	EmbCfgOllamaChecked  bool // true after status check completes
	EmbCfgPulling        bool
	EmbCfgStarting       bool
	EmbCfgSpinner        spinner.Model

	// Embedding config — provider/model change detection
	EmbCfgOriginalProvider int
	EmbCfgOriginalModel    string
	EmbCfgReindexWarning   bool
	EmbCfgReindexing       bool
	EmbCfgReindexProgress  string
	ReindexProgressBar     progress.Model
	ReindexTotal           int
	ReindexDone            int

	// Activity sparkline (7-day observation counts)
	ActivityData []int

	// Split pane preview
	PreviewVisible  bool
	PreviewViewport viewport.Model
	FocusedPane     int // 0=main, 1=preview

	// Toast messages
	ToastMessage string
	ToastType    string // "success", "warning", "error"

	// Delete confirmation
	ConfirmDelete     bool
	ConfirmDeleteID   int64
	DeleteTargetTitle string

	// Command palette
	CmdPaletteOpen   bool
	CmdPaletteInput  textinput.Model
	CmdPaletteCursor int

	// List components (bubbles/list)
	SearchListModel  list.Model
	RecentList       list.Model
	SessionListModel list.Model
	GraphListModel   list.Model
	ArchiveList      list.Model
	// contains filtered or unexported fields
}

Model holds the TUI state.

func New

func New(deps *Deps) Model

New creates a new TUI model connected to the given stores.

func (Model) Init added in v1.0.0

func (m Model) Init() tea.Cmd

Init loads initial data (stats for the dashboard).

func (Model) Update added in v1.0.0

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

func (Model) View added in v1.0.0

func (m Model) View() string

type Screen added in v1.0.0

type Screen int

Screen represents the current TUI view.

const (
	ScreenDashboard Screen = iota
	ScreenSearch
	ScreenSearchResults
	ScreenRecent
	ScreenObservationDetail
	ScreenTimeline
	ScreenSessions
	ScreenSessionDetail
	ScreenSetup
	ScreenGraph
	ScreenArchive
	ScreenHealth
	ScreenEmbeddingConfig
	ScreenHelp
)

Jump to

Keyboard shortcuts

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