Documentation
¶
Overview ¶
Package tui implements the agentop Bubble Tea interactive terminal UI.
Index ¶
- Constants
- func ApplyBackground(pickPalette bool, query func() termenv.Color)
- func ApplyTheme(env, setting, fgbg string) (string, error)
- func ApplyZebra(env, setting string) error
- func ColorizeJSON(v any) string
- func ColorizeJSONBytes(data []byte) string
- func LoadSessionMetadata(path string) map[string]SessionMetadata
- func New(ctx context.Context, c *apiclient.Client, opts ...Option) tea.Model
- func QueryTerminalBackground() termenv.Color
- func Run(ctx context.Context, opts RunOptions) error
- func SessionMetadataPath() (string, error)
- type ColumnSetting
- type EventSettings
- type HarvestFunc
- type Option
- type RunOptions
- type SessionMetadata
- type TimelineSettings
- type UsageSettings
- type UserSettings
Constants ¶
const SessionMetadataRel = claude.SessionMetadataRel
SessionMetadataRel is the harvested metadata file, relative to the user's home. Re-exported from core/observe/claude so this package's readers and its tests keep one spelling; a const cannot be aliased.
const ThemeEnv = "AGENTOP_THEME"
ThemeEnv is the variable that picks the palette.
const ZebraEnv = "AGENTOP_ZEBRA"
ZebraEnv is the variable that turns the stripe on or off.
Variables ¶
This section is empty.
Functions ¶
func ApplyBackground ¶
ApplyBackground asks the terminal for its background, through query, when something uses the answer: the palette when ApplyTheme left the choice to the terminal (pickPalette), and the stripe while it is on. Run it before the viewer starts: it is then the only time agentop asks, because lipgloss does not ask again once the palette is set, and a question asked from inside the viewer races bubbletea for the answer.
The palette is chosen as lipgloss would choose it from the same answer. The stripe is derived only from a real answer; termenv's fallback says nothing about the exact colour.
func ApplyTheme ¶
ApplyTheme sets the palette before the first render, from AGENTOP_THEME (env), the user config's theme (setting), and COLORFGBG (fgbg). It returns what it chose ("light", "dark" or "" when it left the choice to lipgloss) and an error naming a value it did not understand, which is then ignored.
func ApplyZebra ¶
ApplyZebra sets the stripe before the first table is built, from AGENTOP_ZEBRA (env) and the user config's zebra (setting). It returns an error naming a value it did not understand, which is then ignored. Call it before ApplyBackground, which replaces an on stripe.
func ColorizeJSON ¶
ColorizeJSON takes a Go value (typically something decoded from json) and returns an indented, colorized string, every fold open. A multi-line string renders as an indented block rather than one quoted line — see detail_tree.go.
func ColorizeJSONBytes ¶
ColorizeJSONBytes parses data then colorizes. Falls back to a muted raw string on parse failure so the caller always gets something renderable.
func LoadSessionMetadata ¶
func LoadSessionMetadata(path string) map[string]SessionMetadata
LoadSessionMetadata reads the harvested titles, degrading to none rather than failing.
It never returns an error, for the reason loadUserConfig does not: this file is a convenience cache another command produces, and a missing or corrupt one must not keep the viewer from opening — the viewer being the tool you reach for when everything else is broken. Every failure yields an empty map: the pane still works, it just cannot name anything FROM HERE.
AND THE COLUMN NO LONGER GOES BLANK WITH IT. This used to say a failure "renders as an empty TITLE column", which stopped being true when sessionTitleFor gained the fallback to the title /v1/sessions serves: a session the proxy has named still renders one through a total load failure. Degrading to none is therefore less visible than it was, which is the right direction and worth stating so the silence stays justified.
Absent is not a failure at all. Nobody has this file until they run `agentop experimental read-claude-sessions`, so a first run must be silent rather than scolded.
Silent on a corrupt file rather than warning, unlike loadUserConfig: that one reports a broken settings file because the user WROTE it and their edit is being ignored. This file is machine-generated, so the actionable answer is to re-run the harvester, and there is nowhere safe to say so — the caller loads it while building the model, and once tea.NewProgram takes the alt screen anything written to the terminal corrupts the frame instead of reaching anyone.
func New ¶
New returns a fresh model pointed at the given client. ctx governs both the HTTP calls and the SSE goroutine; cancelling it shuts everything down.
func QueryTerminalBackground ¶
QueryTerminalBackground asks the terminal for its background as lipgloss would: a termenv.RGBColor when the terminal answered, termenv's fallback when it did not (COLORFGBG, else black), and nil when stdout is not a terminal. Windows terminals are never asked.
func Run ¶
func Run(ctx context.Context, opts RunOptions) error
Run starts the bubbletea program. See RunOptions for mode selection.
func SessionMetadataPath ¶
SessionMetadataPath returns ~/.cortex/session-metadata.json.
Types ¶
type ColumnSetting ¶
ColumnSetting is one column's visibility, keyed by the stable id the picker shows as its header (#, TIME, DIR, …). Keyed by name rather than position because eventColumns' order is a display decision that may change; see the eventColumnID doc comment.
type EventSettings ¶
type EventSettings struct {
// Columns records only DEVIATIONS from the defaults — a column absent here takes
// its own default, which since #1309 is visible for every column there is. Two
// consequences, both deliberate:
//
// A column added in a later build shows up for everyone who already has a
// config file, instead of starting hidden because their file predates it. And
// the file stays legible: turn two columns off and it has two entries, not
// thirteen.
//
// The alternative (a list of what is ON) reads more obviously but inverts both
// of those, since every column is defaultOn. Note the scheme still has to
// round-trip a default-OFF column — a future one, or BYTES again — which is why
// the tests for that exercise a synthetic column rather than a real one.
Columns []ColumnSetting `yaml:"columns,omitempty"`
// SortColumn is the events-table sort column, by the same stable id the picker
// shows as a header (#865). Empty — the zero value, and what every file written
// before this existed carries — means CHRONOLOGICAL, so an older config restores
// exactly today's behaviour.
SortColumn string `yaml:"sortColumn,omitempty"`
// SortDesc is that sort's direction. Only meaningful with SortColumn set; false
// on its own is simply the ascending half of a sort that is not active.
SortDesc bool `yaml:"sortDesc,omitempty"`
// OpenAtOldest places the cursor on the OLDEST event when a session is opened,
// instead of the newest.
//
// Set by `g` and cleared by `G` — the two keys that already mean "go to an end",
// so the preference is whichever end the operator last deliberately jumped to.
// That needs no new binding and teaches itself: press g, leave the session, come
// back, and it opened where you were.
//
// False is the default, and what every file written before this carries, which is
// the behaviour agentop has always had: a session opens at the newest event and
// follows the tail from there.
//
// The ENTRY point only. Once open, tail-follow is still governed by whether the
// cursor sits on the newest row (see rebuildEventsTable), so opening at the
// oldest simply means the operator is not at the tail and arriving events append
// below them instead of dragging the cursor along.
OpenAtOldest bool `yaml:"openAtOldest,omitempty"`
}
EventSettings is the events-table view state.
type HarvestFunc ¶
type HarvestFunc func() (map[string]SessionMetadata, error)
HarvestFunc reads an agent's transcripts and returns what it learned, keyed by session id.
A function on RunOptions rather than a direct call into core/observe/claude, so this package keeps knowing nothing about where titles come from: it renders a map. main supplies the Claude Code implementation, and a test supplies a stub without needing a transcript tree on disk.
Returning the map rather than writing the file is deliberate. The harvester still persists to ~/.cortex/session-metadata.json — that is what makes the NEXT launch instant — but the running viewer must not have to re-read a file it already has a newer version of in memory.
type Option ¶
type Option func(*model)
Option configures a model at construction time.
func WithClock ¶
WithClock replaces the clock event timestamps are measured against. No production caller: the README demo feeds a server running on a shifted clock, and without the same shift here every session would read as days old and render as an absolute date.
func WithoutTitleScroll ¶
func WithoutTitleScroll() Option
WithoutTitleScroll keeps the selected row's TITLE cell static. No production caller: the README demo needs the same frame on each run, and its pump waits for the ticks to stop.
type RunOptions ¶
type RunOptions struct {
Endpoint string
Lister cluster.Lister
PortForwarder cluster.PortForwarder
// LocalEndpoint overrides where `[L]` connects. Empty means
// defaultLocalEndpoint.
LocalEndpoint string
// LocalConfigPath and LocalStatsURL describe the Cortex running on this
// machine: the config file it was started with, and where it serves
// /reload/status. Together they let `e` edit its pipeline directly —
// no kubectl, no ConfigMap, since the proxy already watches that file.
//
// Set only alongside LocalEndpoint, i.e. only when a local Cortex
// answered. Either left empty disables local editing rather than
// half-enabling it, because an apply we cannot confirm reloaded is
// worse than an edit we declined to start.
LocalConfigPath string
LocalStatsURL string
// Save persists the user's settings whenever one changes. Deliberately not a
// list of the keypresses that trigger it: the list was already stale once, and
// the triggers live with the settings they write. A callback rather than a path
// keeps $HOME and the YAML out of this package, so its tests need neither.
//
// Nil disables persistence: what tests pass, and what main passes when there is
// no resolvable home directory to write to.
Save func(UserSettings) error
// Harvest reads session titles from a coding agent's own transcripts, in the
// background, once the UI is up.
//
// Nil means no harvest: what tests pass, and what main passes under
// --skip-claude-metadata. The viewer then shows whatever the metadata file already
// held — the titles from the last run — so this only ever ADDS names.
Harvest HarvestFunc
// Version names this build on the title bar. Empty shows the name alone.
Version string
// UpdateFile is ~/.cortex/update.json. Empty shows no update notice.
UpdateFile string
// ServiceInstall is true when the laptop service unit exists.
ServiceInstall bool
// contains filtered or unexported fields
}
RunOptions selects the entry mode for agentop's TUI.
If Endpoint is non-empty, agentop skips the picker and connects directly to that URL — preserving the pre-picker behavior (and the documented `--endpoint` flag).
Otherwise, agentop uses Lister + PortForwarder to render the picker. Both must be non-nil in picker mode.
type SessionMetadata ¶
type SessionMetadata = claude.SessionMetadata
SessionMetadata is what a coding agent knows about one of its own sessions that Cortex does not. Owned by core/observe/claude, which is where its documentation lives.
An ALIAS, not a distinct type. The shape is the on-disk contract between the harvester and this reader, and core cannot import tui, so the definition had to move there — but aliasing means map[string]SessionMetadata here and map[string]claude.SessionMetadata there are the SAME type, so every consumer in this package keeps its own spelling and assigns what the harvester returns with no conversion.
type TimelineSettings ¶
type TimelineSettings struct {
Window string `yaml:"window,omitempty"`
}
TimelineSettings is the Timeline pane's view. Window is a label from timelineWindows (5m, 1h, 24h, all); empty or unknown means the first.
type UsageSettings ¶
type UsageSettings struct {
// Metric is the metric name as usageMetric.String() renders it: tokens,
// requests, errors or latency. Empty means tokens, the zero value the pane
// starts with.
Metric string `yaml:"metric,omitempty"`
// Window is the window duration as time.Duration.String() renders it (10m0s,
// 1h0m0s, 6h0m0s). Empty, or a duration no longer offered, means the first
// entry in usageWindows.
Window string `yaml:"window,omitempty"`
// Group is the breakdown, by the same string the /v1/usage group parameter
// takes. Empty means ungrouped.
//
// Deliberately not enumerated here, and not validated against a local list:
// usage.ParseGroup owns which values are legal, and it accepts more than the
// [b] cycle visits — a hand-edited file naming one of those is honoured. A copy
// of the set here would be a second place to update, and would have been wrong
// already: the API gained groupings after this comment would have been written.
Group string `yaml:"group,omitempty"`
}
UsageSettings is the usage pane's view state: which metric, window and breakdown the operator last chose.
Stored by NAME, not by the int the pane holds. usageMetric is an iota and the window is an index into usageWindows, so a raw number would silently change meaning if either list were ever reordered or had an entry inserted — the same trap ColumnSetting avoids by keying on the column id. A name this build does not recognise falls back to the default, which is also what an older file with none of these keys gets.
type UserSettings ¶
type UserSettings struct {
Events EventSettings `yaml:"events,omitempty"`
Usage UsageSettings `yaml:"usage,omitempty"`
// Timeline is the Timeline pane's window.
Timeline TimelineSettings `yaml:"timeline,omitempty"`
// Theme is light, dark or auto (the default); AGENTOP_THEME overrides it (theme.go).
Theme string `yaml:"theme,omitempty"`
// Zebra is on (the default) or off: the stripe on every second table row. AGENTOP_ZEBRA
// overrides it (zebra.go).
Zebra string `yaml:"zebra,omitempty"`
}
UserSettings is the persisted shape. Every field is optional: a file written by an older agentop must not disable a setting it never knew about, so the zero value has to mean "use the default" for each one.
var Settings UserSettings
Settings is agentop's live user settings, global to the process.
One struct rather than the fields it replaces (eventColumns, filter) scattered across the model: persisting a new setting then means adding a field here and a save call at the keypress that changes it, rather than finding every place the value is read. It is also what gets marshalled, so the file's shape and the in-memory shape cannot drift.
Package-level because there is exactly one agentop TUI per process — bubbletea owns the terminal, so a second model in the same process has nowhere to render. Threading this through both constructors and every handler would buy testability the callback in RunOptions already provides.
The cost is real and worth naming: tests share it, so each one that touches Settings must reset it (resetSettingsForTest), and t.Parallel is unavailable in this package. Nothing here is parallel today, and t.Setenv in the yank tests already forbids it independently.
Source Files
¶
- agent_scope.go
- agents_other.go
- agents_pane.go
- agents_projects.go
- app.go
- box.go
- clear.go
- colorspace.go
- console_other.go
- cost_event.go
- deps.go
- detail_fetch.go
- detail_pane.go
- detail_raw.go
- detail_tree.go
- edit_overlay.go
- empty_state.go
- events_blocks.go
- events_columns.go
- events_pane.go
- footer.go
- help_overlay.go
- json_colorize.go
- keys.go
- layout.go
- linked.go
- namespaces_pane.go
- open_at.go
- paging.go
- pending_bucket.go
- pipeline_pane.go
- plugin_detail_pane.go
- plugin_metrics.go
- pods_pane.go
- prune_saving.go
- rename.go
- search.go
- search_details.go
- search_rows.go
- search_surfaces.go
- searchdoc.go
- server_picker.go
- server_route.go
- session_metadata.go
- sessions_context.go
- sessions_pane.go
- sessions_title.go
- sessions_title_scroll.go
- settings.go
- spend.go
- spend_band.go
- spend_drawer.go
- spend_strip.go
- spend_tiers.go
- styles.go
- subprocess.go
- table_cursor.go
- table_width.go
- theme.go
- timeline_layout.go
- timeline_pane.go
- tool_enter.go
- tool_rows.go
- update_notice.go
- usage_glyphs.go
- usage_pane.go
- usage_render.go
- usage_stacked.go
- usage_whiskers.go
- util.go
- yank.go
- zebra.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package find is agentop's text matcher: the one place that decides what a search query matches and where, for the table copy and the TUI alike.
|
Package find is agentop's text matcher: the one place that decides what a search query matches and where, for the table copy and the TUI alike. |
|
Package table provides a simple table component for Bubble Tea applications.
|
Package table provides a simple table component for Bubble Tea applications. |