progress

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package progress provides progress reporting for indexing operations.

The Coordinator collects progress events from indexers and aggregates them for display. It tracks per-indexer state (running, done, errored) and counts of processed items.

The UI component (ui.go) provides a bubbletea-based terminal UI that displays real-time progress with spinners, counters, and ETA estimates.

Usage:

coord := progress.NewCoordinator()
// Pass coord.Events() to indexers
// Run bubbletea with progress.NewModel(coord)
// Call coord.Close() when indexing completes

Package progress provides event types and coordination for tracking indexer progress.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatSummary

func FormatSummary(summaries []IndexerSummary, totalDuration time.Duration) string

FormatSummary formats the final summary grouped by phase. Phases appear in the order they are first seen across summaries. Each row is prefixed with ✓ (completed) or ✗ (error).

Types

type Coordinator

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

Coordinator collects progress events from indexers and tracks their state.

func NewCoordinator

func NewCoordinator() *Coordinator

NewCoordinator creates a new progress coordinator.

func (*Coordinator) Close

func (c *Coordinator) Close()

Close stops the coordinator's event processing.

func (*Coordinator) Errors

func (c *Coordinator) Errors() []IndexerError

Errors returns all errors collected from indexers.

func (*Coordinator) Events

func (c *Coordinator) Events() chan<- Event

Events returns the channel to send events to.

func (*Coordinator) IsClosed added in v0.8.0

func (c *Coordinator) IsClosed() bool

IsClosed returns true after Close() has been called and all queued events have been processed. The TUI uses this to know it is safe to exit — it must NOT exit based on IsRunning() alone because PostIndexers (e.g. embeddings) run after the main indexers complete and their progress events would be missed if the TUI quit too early.

func (*Coordinator) IsRunning

func (c *Coordinator) IsRunning() bool

IsRunning returns true if any indexer is still running.

func (*Coordinator) State

func (c *Coordinator) State() []*IndexerState

State returns a copy of the current indexer states in order of first appearance.

func (*Coordinator) Summary

func (c *Coordinator) Summary() []IndexerSummary

Summary returns final statistics for all indexers in order of appearance.

type DoneMsg

type DoneMsg struct{}

DoneMsg is sent when all indexers have completed.

type Event

type Event struct {
	// Indexer is the name of the indexer (e.g., "fs", "git").
	Indexer string

	// Type is the event type.
	Type EventType

	// Current is the number of items processed so far.
	Current int

	// Total is the total number of items to process (0 if unknown).
	Total int

	// Item is the current item being processed (optional, for display).
	Item string

	// Error is set when Type is EventError.
	Error error

	// Timestamp is when the event occurred.
	Timestamp time.Time

	// Phase is the optional display group for this indexer (e.g. "Indexing",
	// "Vectorizing"). Empty means the coordinator will use "Indexing" as default.
	Phase string
}

Event represents a progress update from an indexer.

func Completed

func Completed(indexer string, total int) Event

Completed creates a completed event.

func Error

func Error(indexer string, err error) Event

Error creates an error event.

func NewEvent

func NewEvent(indexer string, eventType EventType) Event

NewEvent creates a new progress event with the current timestamp.

func Progress

func Progress(indexer string, current int, item string) Event

Progress creates a progress event.

func ProgressWithTotal

func ProgressWithTotal(indexer string, current, total int, item string) Event

ProgressWithTotal creates a progress event with a known total.

func Started

func Started(indexer string) Event

Started creates a started event.

func StartedInPhase added in v0.8.0

func StartedInPhase(indexer, phase string) Event

StartedInPhase creates a started event tagged with a phase label. Use this for indexers that belong to a named display group (e.g. "Vectorizing").

type EventType

type EventType int

EventType represents the type of progress event.

const (
	// EventStarted indicates an indexer has started.
	EventStarted EventType = iota
	// EventProgress indicates progress has been made.
	EventProgress
	// EventCompleted indicates an indexer has finished successfully.
	EventCompleted
	// EventError indicates an indexer encountered an error.
	EventError
)

type IndexerError

type IndexerError struct {
	Indexer string
	Err     error
}

IndexerError records an error from a specific indexer.

type IndexerState

type IndexerState struct {
	Name      string
	Status    string // "running", "completed", "error"
	Phase     string // display group ("Indexing", "Vectorizing", …); empty = "Indexing"
	Current   int
	Total     int
	Item      string
	Error     error
	StartedAt time.Time
	EndedAt   time.Time
	// contains filtered or unexported fields
}

IndexerState tracks the current state of an indexer.

func (*IndexerState) ETA

func (s *IndexerState) ETA() time.Duration

ETA returns the estimated time remaining based on current rate. Returns 0 if total is unknown or rate is too low.

func (*IndexerState) Elapsed

func (s *IndexerState) Elapsed() time.Duration

Elapsed returns the duration since the indexer started. If completed/errored, returns the total duration.

func (*IndexerState) Rate

func (s *IndexerState) Rate() float64

Rate returns the current items/second rate (smoothed over recent samples).

type IndexerSummary

type IndexerSummary struct {
	Name     string
	Phase    string // display group ("Indexing", "Vectorizing", …); empty = "Indexing"
	Status   string // "completed", "error"
	Duration time.Duration
	Items    int
	Rate     float64
	Error    error
}

IndexerSummary contains final statistics for an indexer.

type Model

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

Model is the bubbletea model for progress display.

func NewModel

func NewModel(coord *Coordinator) Model

NewModel creates a new progress UI model.

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model.

func (Model) Update

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

Update implements tea.Model.

func (Model) View

func (m Model) View() string

View implements tea.Model.

Jump to

Keyboard shortcuts

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