ui

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ui is the agentscope screen: a ViewModel that holds ALL state as go-widgets/mvvm primitives and never references a widget, and a View (scene.go) that builds toolkit widgets and binds them to it. Both are tagless, so a native `go test` covers them; the browser host is cmd/agentscope-web.

Index

Constants

View Source
const (
	// MaxGraphSessions is how many session clusters are drawn, newest first.
	MaxGraphSessions = 64
	// MaxGraphAgents is how many sub-agent nodes a session cluster shows; the
	// rest are one "+N more" node.
	MaxGraphAgents = 6
	// MaxGraphRepos is how many repositories the "other repositories" cluster
	// shows (held repositories are always drawn, inside their holder).
	MaxGraphRepos = 200

	// NodeWidth is the width of a node box, and NodeChars the number of
	// characters a label is cut to so that it fits in it.
	NodeWidth = 170
	NodeChars = 22
)

The GraphView sizes each cluster by its own members and scrolls when they overflow, so these are safety bounds on what is drawn, not a fit to the screen. They are the screen's, not the collector's: the table and the detail pane list everything.

View Source
const (
	SpanShort = iota // the 5 hour window
	SpanWeek         // the 7 day window
	SpanWeeks        // four 7 day windows, aligned on the weekly reset
)

The spans the Quota tab can show, in the order of the selector.

View Source
const (
	KindOutput = iota
	KindCacheRead
)

The token kinds the weeks view can show, in the order of the selector.

View Source
const (
	DefaultW = 1280
	DefaultH = 800
)

DefaultW and DefaultH are the size a Scene has before the host tells it the viewport's.

View Source
const (
	TabGraph = iota
	TabQuota
)

The tabs.

View Source
const AllAccounts = "All (aggregated)"

AllAccounts is the first option of the account selector: every account, aggregated.

View Source
const ModelChipSlots = 3

ModelChipSlots is how many model families the header shows chips for.

Variables

View Source
var (
	SpanNames = []string{"5 h", "7 days", "4 x 7 days"}
	KindNames = []string{"output", "cache read"}
)

SpanNames and KindNames label the selectors.

View Source
var Brand = toolkit.RGB(0x00, 0x79, 0xA8)

Brand is agentscope's accent: the go-authn account page's brand colour.

Functions

func AccountOptions added in v0.8.0

func AccountOptions(u *model.Usage) []string

AccountOptions are the selector's options: All, then every account, the active one marked.

func Palette added in v0.6.0

func Palette(dark bool) []toolkit.RGBA

Palette is the graph's category palette: the Okabe-Ito order, which is safe under the common colour-vision deficiencies, with its lightness tuned to the page: eased toward the Slate ground in light, lifted a little in dark so a pill keeps its contrast against the dark card. The order is what the legend and the colour assignment (by first appearance) rely on, so it is never reordered.

func RepoLabel added in v0.3.0

func RepoLabel(key string, max int) string

RepoLabel is org/repo cut to at most max characters. When it does not fit, the ORG is shortened (with an ellipsis) and the repo is kept whole; only a repo name longer than the room itself is cut.

func StackColors added in v0.7.0

func StackColors(dark bool) []toolkit.RGBA

StackColors are the families' colours, in the order of model.Usage.Families: four of the Okabe-Ito set, which stays apart under colour-vision deficiency.

func Tokens added in v0.7.0

func Tokens(v float64) string

Tokens writes a token count as "1.2M" or "340k".

Types

type CapRow added in v0.8.0

type CapRow struct {
	Account, Session, Weekly, Left, Resets, Active string
}

CapRow is one line of the capacity table.

func (CapRow) Cells added in v0.8.0

func (r CapRow) Cells() []string

Cells are the row's cells.

type Row

type Row struct {
	ID    string // session short id
	State string
	Repo  string
	Task  string
	Last  string
	Agent string // sub-agent count
	Model string // short family name ("Opus 5.5"), or "?" when unknown or unseen
}

Row is one line of the sessions table.

func (Row) Cells

func (r Row) Cells() []string

Cells is the row as the table shows it.

func (Row) Text

func (r Row) Text() string

Text is the row's whole text, which is what the query is matched against.

type Scene

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

Scene is the View: the widgets, their layout, and the bindings to the ViewModel. It never assigns a widget's state field itself, and draws nothing by hand: every surface is a toolkit widget (Frame cards, Chips, the graph, the charts, the side panel in a toolkit Overlay).

func NewScene

func NewScene(w, h int) *Scene

NewScene builds the View over a fresh ViewModel, at 1x.

func (*Scene) Dirty

func (s *Scene) Dirty() bool

Dirty reports, and clears, the repaint-needed flag.

func (*Scene) Draw

func (s *Scene) Draw(buf []byte)

Draw paints the scene onto buf, an RGBA row-major slice of w*h pixels.

func (*Scene) HandleChar

func (s *Scene) HandleChar(ch string) bool

HandleChar routes a printable character to the focused widget; "t" outside the search box toggles the side panel.

func (*Scene) HandleClick

func (s *Scene) HandleClick(x, y int) bool

HandleClick dispatches a click at surface (x, y) to the widget under it. A click on the open panel never reaches the graph beneath it.

func (*Scene) HandleKeyDown

func (s *Scene) HandleKeyDown(code string) bool

HandleKeyDown routes a named key to the focused widget.

func (*Scene) HandleMove

func (s *Scene) HandleMove(x, y int) bool

HandleMove routes pointer motion to the widget grabbed on press.

func (*Scene) HandleRelease

func (s *Scene) HandleRelease(x, y int) bool

HandleRelease routes a button release to the grabbed widget and drops it.

func (*Scene) HandleScroll

func (s *Scene) HandleScroll(x, y, delta int) bool

HandleScroll routes a wheel scroll (Delta in rows, positive = down) to the scrollable under the pointer.

func (*Scene) PanelVisible added in v0.7.0

func (s *Scene) PanelVisible() bool

PanelVisible is whether the side panel is on screen: open, over the graph.

func (*Scene) Resize added in v0.7.0

func (s *Scene) Resize(w, h int, scale float64)

Resize makes the scene w by h device pixels at the given device pixel ratio and lays it out again: the graph takes every pixel the header and the tabs do not, and its clusters flow into as many columns as the width holds. A resize may re-lay-out the graph; an edge update never does.

func (*Scene) Size added in v0.7.0

func (s *Scene) Size() (w, h int)

Size is the scene's size in device pixels.

func (*Scene) VM

func (s *Scene) VM() *ViewModel

VM is the ViewModel the host feeds snapshots to.

type ViewModel

type ViewModel struct {
	// Graph is what the GraphView shows; its Selected and Filter are the
	// widget's own observables.
	Graph *toolkit.GraphViewModel
	// Query is the search entry's text. It dims the graph (Graph.Filter) and
	// narrows the table.
	Query *mvvm.Observable[string]
	// Rows is the sessions table; TableSel is its selected row index.
	Rows     *mvvm.ObservableList[Row]
	TableSel *mvvm.Observable[int]
	// Detail is the detail pane: the selection's facts, or the anomalies when
	// nothing is selected.
	Detail *mvvm.ObservableList[string]
	// Status is the one-line summary; Conn is the connection state.
	Status *mvvm.Observable[string]
	Conn   *mvvm.Observable[string]
	// ShowExpired draws the edges to a selected session's expired leases
	// (hidden by default: the detail pane lists them). Expanded is the orgs of
	// the "other repositories" cluster that are open.
	ShowExpired *mvvm.Observable[bool]
	Expanded    *mvvm.ObservableList[string]
	// Dark is the system's colour-scheme preference, set by the host (a
	// browser's prefers-color-scheme) and followed when it changes.
	Dark *mvvm.Observable[bool]
	// ModelChips are the header's model-count chips: the three most used model
	// families ("Sonnet 29"), "" for a slot with none.
	ModelChips [ModelChipSlots]*mvvm.Observable[string]

	// Tab is the shown tab: TabGraph or TabQuota.
	Tab *mvvm.Observable[int]
	// PanelOpen is whether the side panel (the sessions table and the details)
	// is open over the graph; it starts closed, TogglePanel flips it, and
	// selecting a node opens it.
	PanelOpen   *mvvm.Observable[bool]
	TogglePanel *mvvm.Command
	// Span is the Quota tab's span (SpanShort, SpanWeek, SpanWeeks) and Kind the
	// token kind its 4 x 7 days charts show.
	Span, Kind *mvvm.Observable[int]
	// Usage is the Quota tab's data, from the last snapshot.
	Usage *mvvm.Observable[*model.Usage]
	// QuotaNotes is the line under the Quota charts: what is not available, what
	// is not recorded, where the reset came from.
	QuotaNotes *mvvm.Observable[string]
	// Account is the account selector's choice: 0 is AllAccounts, i is the i-th
	// account of the usage. AccountOptions are its options and Capacity the
	// capacity table's rows, both rebuilt when the usage changes; the selection
	// follows its account (by key) across a rebuild.
	Account        *mvvm.Observable[int]
	AccountOptions *mvvm.ObservableList[string]
	Capacity       *mvvm.ObservableList[CapRow]
	// contains filtered or unexported fields
}

ViewModel is the whole screen's state.

func NewViewModel

func NewViewModel() *ViewModel

NewViewModel returns a ViewModel showing nothing yet.

func (*ViewModel) Apply

func (vm *ViewModel) Apply(s model.Snapshot)

Apply shows a snapshot. A list is replaced only when it differs, so a graph whose members did not change does not lay itself out again.

func (*ViewModel) CollapseAll added in v0.4.0

func (vm *ViewModel) CollapseAll()

CollapseAll folds every org again (Escape).

func (*ViewModel) Snapshot

func (vm *ViewModel) Snapshot() (model.Snapshot, bool)

Snapshot is the last snapshot applied.

func (*ViewModel) ToggleOrg added in v0.4.0

func (vm *ViewModel) ToggleOrg(selection string)

ToggleOrg expands or collapses an org of the "other repositories" cluster: what activating (Enter, a second click on) its node does. selection is the graph's Selected value; anything that is not an org node is ignored.

Jump to

Keyboard shortcuts

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