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
- Variables
- func AccountOptions(u *model.Usage) []string
- func CapDPR(cssW, cssH int, dpr float64) float64
- func ClampColW(col, w int) int
- func ClampPanelW(w, viewW int) int
- func ClampSplit(v int) int
- func Palette(dark bool) []toolkit.RGBA
- func PressureColor(band int, dark bool) toolkit.RGBA
- func RepoLabel(key string, max int) string
- func StackColors(dark bool) []toolkit.RGBA
- func Tokens(v float64) string
- type CapRow
- type CtxRow
- type Feed
- type Filters
- type GuardRow
- type GuardState
- type RenameState
- type Row
- type Scene
- func (s *Scene) Cursor(x, y int) string
- func (s *Scene) Dirty() bool
- func (s *Scene) Draw(buf []byte)
- func (s *Scene) HandleChar(ch string) bool
- func (s *Scene) HandleClick(x, y int) bool
- func (s *Scene) HandleKeyDown(code string) bool
- func (s *Scene) HandleMove(x, y int) bool
- func (s *Scene) HandleRelease(x, y int) bool
- func (s *Scene) HandleScroll(x, y, delta int) bool
- func (s *Scene) PanelVisible() bool
- func (s *Scene) Resize(w, h int, scale float64)
- func (s *Scene) SetStore(st Store)
- func (s *Scene) Size() (w, h int)
- func (s *Scene) VM() *ViewModel
- type Store
- type ViewModel
Constants ¶
const ( StateAll = iota StateActive StateIdle )
The state filter's choices.
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.
const ( GColName = iota GColTotal GColLast GColDecision GColGate GColAfter GColFlag )
The columns of the lessons table.
const ( PanelMinW = 320 PanelDefaultW = 420 PanelMaxPercent = 70 )
The side panel's width, in logical pixels: it opens at PanelDefaultW, the owner may drag its left edge, and it stays between PanelMinW and PanelMaxPercent of the surface.
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.
const ( KindOutput = iota KindCacheRead )
The token kinds the weeks view can show, in the order of the selector.
const ( DefaultW = 1280 DefaultH = 800 )
DefaultW and DefaultH are the size a Scene has before the host tells it the viewport's.
const ( TabGraph = iota TabQuota TabGuardrails )
The tabs.
const ( SplitScale = 1000 // the two panes' shares add up to this SplitDefault = 550 // Sessions 55 %, Details 45 %: what a double-click on the divider restores SplitLo = 100 // a stored or set share is held between these SplitHi = 900 PaneMinH = 120 // the least height, in logical pixels, either pane keeps )
The split between the Sessions table and the Details pane inside the side panel: the owner drags the divider between them. Split is the Sessions pane's share of the two, in thousandths; each pane keeps at least PaneMinH logical pixels.
const AllAccounts = "All (aggregated)"
AllAccounts is the first option of the account selector: every account, aggregated.
const AllRepos = "All repositories"
AllRepos is the first option of the repository drop-down.
const GraphMinW = 320
GraphMinW is the least width, in logical pixels, the graph keeps beside the open panel: the splitter squeezes the panel before it takes more.
const GuardChipSlots = 4
GuardChipSlots is how many headline chips the tab shows.
const MaxBackingPixels = 8_000_000
MaxBackingPixels bounds the canvas's backing store, in device pixels: a full-surface canvas at a high devicePixelRatio is hundreds of megabytes of pixels that a browser's compositor keeps copies of (a 5K display at 2x is 30 M pixels, 120 MB per copy).
const ModelChipSlots = 3
ModelChipSlots is how many model families the header shows chips for.
const ModelFilterSlots = 6
ModelFilterSlots is how many model names the filter row offers a check box for: the most used ones present.
Variables ¶
var ( LastNames = []string{"Any activity", "< 10 min", "< 1 h", "< 6 h", "< 24 h"} LastLimits = []time.Duration{0, 10 * time.Minute, time.Hour, 6 * time.Hour, 24 * time.Hour} )
LastNames are the last-activity drop-down's options; LastLimits the age each keeps (0: any), in the same order.
var ( ColTitles = []string{"State", "Session", "Context", "Model", "Repository", "Task", "Last", "Agents"} ColMin = []int{40, 50, 80, 50, 60, 60, 30, 44} ColDefault = []int{56, 72, 104, 68, 96, 130, 40, 56} )
The sessions table's columns: their titles, the least width each may be dragged to, and the width each starts at, in logical pixels.
var ( SpanNames = []string{"5 h", "7 days", "4 x 7 days"} KindNames = []string{"output", "cache read"} )
SpanNames and KindNames label the selectors.
var Brand = toolkit.RGB(0x00, 0x79, 0xA8)
Brand is agentscope's accent: the go-authn account page's brand colour.
var DecisionNames = []string{"All decisions", "gate", "pending", "no-gate", "untriaged", "none"}
The Guardrails tab's decision filter: DecisionNames[0] is every decision, the others are the decisions the ledger records.
var GuardTitles = []string{"Lesson", "Recur.", "Last", "Decision", "Gate", "After gate", "Flag"}
GuardTitles are the lessons table's column titles; the columns are sortable.
var StateNames = []string{"All states", "Active", "Idle"}
StateNames are the state drop-down's options, indexed by StateAll...
Functions ¶
func AccountOptions ¶ added in v0.8.0
AccountOptions are the selector's options: All, then every account, the active one marked.
func CapDPR ¶ added in v0.10.1
CapDPR is the device pixel ratio to draw a cssW by cssH viewport at: dpr, or less when the backing store would exceed MaxBackingPixels. A ratio that is not a positive number, or a viewport with no area, gives 1.
func ClampColW ¶ added in v0.9.0
ClampColW is w, a column's width, held between that column's least width and a bound that keeps a hostile stored value from making a table of a million pixels. An unknown column keeps w as it is.
func ClampPanelW ¶ added in v0.9.0
ClampPanelW is w held between PanelMinW and PanelMaxPercent of viewW (both logical pixels). A surface too narrow for the minimum gets the minimum: the panel never becomes unusable.
func ClampSplit ¶ added in v0.10.2
ClampSplit is a Sessions share held between SplitLo and SplitHi. The panes' minimum heights are applied by the layout, against the height the panel has.
func Palette ¶ added in v0.6.0
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 PressureColor ¶ added in v0.9.0
PressureColor is the colour of a pressure band in the light or the dark theme.
func RepoLabel ¶ added in v0.3.0
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
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.
Types ¶
type CapRow ¶ added in v0.8.0
type CapRow struct {
Account, Plan, Session, Weekly, Left, Resets, Active string
}
CapRow is one line of the capacity table.
type CtxRow ¶ added in v0.9.0
type CtxRow struct {
Name string
Text string // "212k / 300k"
Ratio float64 // context / window, 0 when unknown
Band int // model.PressureBand of Ratio
}
CtxRow is one gauge of the Details pane: a session or a sub-agent and how full its context is.
type Feed ¶ added in v0.10.1
type Feed struct {
// contains filtered or unexported fields
}
Feed puts snapshots on the screen as sparingly as the owner can see: nothing is applied while the tab is hidden (the latest one is kept and shown once, when it is visible again), and a snapshot that changes nothing the screen shows repaints nothing (the Scene is only dirty when something it draws changed).
type Filters ¶ added in v0.9.0
type Filters struct {
// State is StateAll, StateActive or StateIdle; Last indexes LastLimits.
State, Last *mvvm.Observable[int]
// Repo is the repository drop-down's choice: 0 is AllRepos, i the i-th of
// RepoOptions. It follows its repository by name when the options change.
Repo *mvvm.Observable[int]
RepoOptions *mvvm.ObservableList[string]
// ModelLabels and ModelOn are the model check boxes: slot i is the i-th most
// used model present, "" when there are fewer. None checked is no model
// filter; checked ones are OR-ed among themselves, AND-ed with the rest.
ModelLabels [ModelFilterSlots]*mvvm.Observable[string]
ModelOn [ModelFilterSlots]*mvvm.Observable[bool]
// Clear puts every filter back to "all".
Clear *mvvm.Command
// contains filtered or unexported fields
}
Filters is what narrows the sessions table: every filter is MVVM state, and they combine with AND (and with the search text).
type GuardRow ¶ added in v0.10.0
type GuardRow struct {
Name string
Total int
Last string
Decision string
Gate string // truncated text
After int
// AfterInferred of After have a year `recur` inferred.
AfterInferred int
Silent bool
}
GuardRow is one lesson of the table.
type GuardState ¶ added in v0.10.0
type GuardState struct {
Data *mvvm.Observable[*model.Guardrails]
Rows *mvvm.ObservableList[GuardRow]
// Sel is the selected table row, Detail the pane showing that lesson.
Sel *mvvm.Observable[int]
Detail *mvvm.ObservableList[string]
// Decision indexes DecisionNames; SortCol and SortAsc order the table.
Decision *mvvm.Observable[int]
SortCol *mvvm.Observable[int]
SortAsc *mvvm.Observable[bool]
// Chips are the headline chips; Notes the line under the tab, which says what
// is not measured.
Chips [GuardChipSlots]*mvvm.Observable[string]
Notes *mvvm.Observable[string]
// contains filtered or unexported fields
}
GuardState is the Guardrails tab's state: the data, the table (filtered by decision and sorted), the selection and what it shows, and the headline chips.
func (*GuardState) SetSort ¶ added in v0.10.0
func (g *GuardState) SetSort(col int, asc bool)
SetSort is what a header click does: it orders the table by col.
type RenameState ¶ added in v0.9.0
type RenameState struct {
// Open is whether the dialog is up; Text the entry's content; Err why the last
// attempt failed ("" when it did not); Busy while the server has the request.
Open *mvvm.Observable[bool]
Text *mvvm.Observable[string]
Err *mvvm.Observable[string]
Busy *mvvm.Observable[bool]
// Begin opens the dialog on the selected account; Confirm sends the name;
// Cancel closes it. Begin can run only with an account selected.
Begin, Confirm, Cancel *mvvm.Command
// Send asks the server to rename account key to name; the host sets it and it
// must not block (the browser's event loop must run for the request to go
// out), reporting back through Done.
Send func(key, name string)
// contains filtered or unexported fields
}
RenameState is the Rename action of the accounts table: a dialog that gives the selected account a display name. It holds all of the dialog's state; the Scene only shows it. Nothing is saved until Confirm: a suggestion (the organisation's name, when the server was started with --show-org) is only the text the entry starts with.
func (*RenameState) Done ¶ added in v0.9.0
func (r *RenameState) Done(err error)
Done is the server's answer to Send: the dialog closes on success and says why on failure, keeping what the owner typed.
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
// CtxText is "212k / 300k", Ratio the context over the compaction window, and
// Band its pressure band (model.PressureBand): what the Context column's
// gauge draws.
CtxText string
Ratio float64
Band int
// Repos is every repository the session holds or sits in, one per line: what
// the Repository filter matches (a session can hold several). Active and Age
// are what the State and Last-activity filters read.
Repos string
Active bool
Age time.Duration
}
Row is one line of the sessions table.
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 (*Scene) Cursor ¶ added in v0.9.0
Cursor is the CSS cursor the pointer at surface (x, y) should show: a horizontal resize over the panel's divider and while it is held, "" (the host's default) elsewhere.
func (*Scene) HandleChar ¶
HandleChar routes a printable character to the focused widget; "t" outside the search box toggles the side panel.
func (*Scene) HandleClick ¶
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 ¶
HandleKeyDown routes a named key to the focused widget.
func (*Scene) HandleMove ¶
HandleMove routes pointer motion to the widget grabbed on press; with nothing grabbed it tracks the pointer over the panel's divider (which lights up). It reports whether the picture changed.
func (*Scene) HandleRelease ¶
HandleRelease routes a button release to the grabbed widget and drops it.
func (*Scene) HandleScroll ¶
HandleScroll routes a wheel scroll (Delta in rows, positive = down) to the scrollable under the pointer.
func (*Scene) PanelVisible ¶ added in v0.7.0
PanelVisible is whether the side panel is on screen: open, over the graph.
func (*Scene) Resize ¶ added in v0.7.0
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) SetStore ¶ added in v0.9.0
SetStore restores the viewer's layout from st and keeps it there as it changes. What is stored is untrusted (another page of the same origin could have written it): it is parsed strictly and clamped, and anything else is ignored.
type Store ¶ added in v0.9.0
Store is where a viewer's layout is kept between visits: the browser's localStorage, through the host. A host whose storage is unavailable passes none, or one that does nothing: the layout is then the default each time.
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]
// Guard is the Guardrails tab's state (see guardrails.go).
Guard *GuardState
// Tab is the shown tab: TabGraph, TabQuota or TabGuardrails.
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]
// Filters narrow the sessions table (AND, with the query).
Filters *Filters
// Contexts are the Details pane's gauges: the selected session and each of its
// sub-agents, or the selected sub-agent.
Contexts *mvvm.ObservableList[CtxRow]
// ViewW is the surface's width in logical pixels (set by the Scene), PanelW the
// side panel's, kept between PanelMinW and PanelMaxPercent of it; ColW the
// sessions table's column widths. All three are persisted per viewer (SetStore).
ViewW, PanelW *mvvm.Observable[int]
ColW *mvvm.ObservableList[int]
// Split is the Sessions pane's share, in thousandths, of the Sessions and Details
// panes stacked in the side panel (see vsplit.go); persisted per viewer too.
Split *mvvm.Observable[int]
// The Rename action of the accounts table: CapSel is the selected row, and
// Rename the dialog's state (see rename.go).
CapSel *mvvm.Observable[int]
Rename *RenameState
// 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 ¶
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) EffectivePanelW ¶ added in v0.9.0
EffectivePanelW is the width the panel is shown at: the chosen PanelW held to the bounds of the surface as it is now.
func (*ViewModel) SetColWidth ¶ added in v0.9.0
SetColWidth is the owner dragging column col to w logical pixels: the width is held at the column's minimum and recorded; a column that does not exist is ignored.