Documentation
¶
Overview ¶
Package view is the dashboard's model: one account's row, and every cell a human table renders it into.
It exists so that a renderer outside package cli can exist at all. Package cli exports nine identifiers and none of them is a row, so a second renderer would have had to spell every percentage, every reset span and every "could not be read" a second time — and the two spellings would agree until the day one of them changed. That `ccdad status`, `ccdad list` and the terminal dashboard can never disagree is a property of there being ONE of each of these, not of three of them being written carefully.
Nothing here reads the clock, the filesystem or the environment. A Row is built from documents somebody else read.
Index ¶
- Constants
- func ActiveLine(claude, codex string) string
- func DaemonLine(report daemon.Report, now time.Time) string
- func DescribeRunning(report daemon.Report, now time.Time) string
- func HoverLine() string
- func HumanDuration(d time.Duration) string
- func ManualLine() string
- func ModeLine(m strategy.Mode) string
- func RunwayAccounts(f forecast.Fleet) string
- func RunwayBurn(b forecast.Band) string
- func RunwayCreditBasis(c forecast.CreditFleet) string
- func RunwayCreditBurn(c forecast.CreditFleet) string
- func RunwayCreditReplenish() string
- func RunwayCreditVerdict(c forecast.CreditFleet, now time.Time, loc *time.Location) string
- func RunwayEmpty(r forecast.AccountRow, now time.Time, loc *time.Location) string
- func RunwayLeft(pct float64) string
- func RunwayLine(f forecast.Fleet, now time.Time, loc *time.Location) string
- func RunwayNeedSegment(f forecast.Fleet) string
- func RunwayReplenish(perHour float64) string
- func RunwayRowCells(r forecast.AccountRow) (window, left, burn string)
- func RunwayVerdict(a forecast.Axis, now time.Time, loc *time.Location) string
- func RunwayWrap(label, line string, width int) string
- func ThresholdsFor(cfg config.Config, now time.Time, plan strategy.Plan, planErr error) (resolve func(uuid string) strategy.Thresholds, notices []string)
- func Timestamp(t time.Time, loc *time.Location) string
- func UpdateLine(report daemon.Report, running string) (string, bool)
- func WindowHeader(n usage.WindowName) string
- func WrapLabeled(line string, width int) string
- type CellState
- type Columns
- type Exec
- type ResetColumn
- type Row
- func (r Row) AgeLabel(now time.Time) string
- func (r Row) CarriedWindows() []usage.NamedWindow
- func (r Row) CellState(n usage.WindowName) CellState
- func (r Row) Cells(c Columns, now time.Time) []string
- func (r Row) CreditLine() (string, bool)
- func (r Row) Empty() (empty, known bool)
- func (r Row) ListLabel() string
- func (r Row) Marker() string
- func (r Row) Reported() (usage.NamedWindow, bool)
- func (r Row) ReportedName() usage.WindowName
- func (r Row) ResetCell(c ResetColumn, now time.Time) string
- func (r Row) StatusFlags() string
- func (r Row) StatusLabel() string
- func (r Row) TierLabel() string
- func (r Row) TypeLabel() string
- func (r Row) WindowCell(n usage.WindowName) string
- func (r Row) WindowPct(n usage.WindowName) (float64, WindowState)
- func (r Row) WindowReset(n usage.WindowName) (time.Time, bool)
- func (r Row) WindowSpent(n usage.WindowName) (spent, known bool)
- type Snapshot
- type WindowColumn
- type WindowState
Constants ¶
const HeaderBudget = 10
HeaderBudget is the widest a window header may be, in display columns.
A scoped cap's display name is arbitrary wire text and the whole name is worse: `weekly_scoped:model:Fable` is 25 columns against a dashboard cell that reserves 20, and nothing between the cell and the terminal cut it, so the overflow came off the right where other columns live.
const NoQuantity = "-"
NoQuantity is what a cell renders when the quantity does not exist here, as against Unreadable's "somebody tried to read it and could not". The two are different verdicts and both appear in one rendered row: an account with no cached reading has an unknown percentage and no window to name, so its USED cell is "?" and its WINDOW cell is "-". Collapsing them would tell a reader that a quantity which cannot exist merely went unread, and send them looking for the reading.
const PlaceholderHeader = "QUOTA"
PlaceholderHeader is the one quota column a table shows when no visible row carried a readable window.
The block is never omitted. A table that simply stopped having quota columns would look like a build with no quota feature rather than like a fleet nobody could read, and the cells under this header are all Unreadable, which is the honest statement.
const Unreadable = "?"
Unreadable is what a value that could not be read renders as. Never "0%" -- unknown is never read as zero, and cswap's version of that bug parked its engine on the account that reset last, because one expired token made every account look empty.
const WarnBand = 10.0
WarnBand is how close to its threshold a cell has to be before it is amber.
It is a DISPLAY constant and not an engine number, which is the whole of its justification: no anti-flap margin means "close", hysteresis_pct can legally be zero, and under hover the engine does not read a configured threshold at all. A named display constant claims only "close to the threshold", claims it in its own name, and no engine number can drift away from it.
Variables ¶
This section is empty.
Functions ¶
func ActiveLine ¶ added in v0.11.0
ActiveLine is who this machine is spending, in one sentence.
It is a free function as well as a method because `ccdad which` has no Snapshot to build and must produce the identical line: two spellings of one sentence is how two commands come to describe one machine two ways, which is the failure this whole package exists to prevent.
With no codex account it is the Claude label ALONE, unlabelled. That is not a degradation -- it is the answer every reader and every script had before there was a second provider, and prefixing it with "Claude:" on a machine with one provider would be labelling a distinction that does not exist there.
func DaemonLine ¶
DaemonLine is the liveness line `ccdad status` prints at the top of the dashboard. It is one of TWO wordings this repository ships, and the other is DescribeRunning below. They are not merged: this one leads a nine-column label field that the Active: and Mode: lines below it line up with, and the other is a fragment that reads as the tail of a sentence.
The default arm is DaemonUnknown and every future value. "Cannot tell" is never folded into "no": a supervisor gating on that folding respawns forever on a filesystem where locks do not work.
func DescribeRunning ¶
DescribeRunning is the one-line human form of a live daemon. now is a parameter rather than a call because nothing in this package reads a clock; package cli passes timeNow(), which is what the old body called.
func HoverLine ¶ added in v0.7.0
func HoverLine() string
HoverLine is the dashboard's one line about the fully automatic mode, and it is printed only when hover is ON.
Absence is unambiguous here, which is what separates it from ModeLine: hover off is the default and the configured numbers are then the ones in force, whereas a missing Mode would have been defaulted to "headroom" -- a plausible answer nobody computed. What it must not be is silent while hover IS on. The Mode line reads "headroom" under hover because hover forced headroom, so a reader who configured consume-first would otherwise see a mode they never asked for with no reason for it anywhere on the page.
It names 'ccdad hover status' rather than printing a number, because there is no single number to print: hover derives one per account and per window. The label column is nine characters wide, matching the Daemon:, Active: and Mode: lines it stacks with.
func HumanDuration ¶
HumanDuration renders a span at the scale a reader cares about. A reset already behind us is "due" rather than a negative number: the endpoint has not rolled the window over yet, which is a real state and not a clock error.
func ManualLine ¶ added in v0.10.0
func ManualLine() string
ManualLine is the dashboard's one line about manual mode, printed only when the mode is ON.
It names `ccdad switch` in the same breath, because the sentence a reader needs is not "ccdad has stopped" but "ccdad has stopped and you have not": every table below this line is still current, and moving the login is still one command. Without that half, a mode a user turned on last week reads as an outage the first time they come back to a spent account.
func ModeLine ¶
ModeLine is the ranking mode with the question it is asking. Recovery is the one a user needs told: the columns are identical to the ordinary case, so nothing else on the dashboard distinguishes "the engine is ranking by soonest reset because everything is spent" from "the engine has nothing to do".
The label column is nine characters wide, matching the Daemon: and Active: lines above it. No branch may contain the substring "exhaust": the human table keeps the projection to --json, and a mode line that used the word would put it back on the page the projection was kept off.
TestNoModeLineBranchSaysExhausted is what makes that red. It asks the question twice -- by rendering every mode this binary declares plus one it has never heard of, and by reading the branches below as source, so a case written for a mode nothing yet passes in is covered too -- and it pins the branch count, because a line added to a block without the test that covers the block growing with it is how this rule came to be held by prose.
func RunwayAccounts ¶ added in v0.7.0
RunwayAccounts is the seat-count line under the axis block: how many accounts the run had to work with, how many it would take to survive the horizon at the measured rate, and the difference between the two.
It answers the axis block's question from the other end. The rows above say how much is left and when it runs out; this says how many seats it would take for it not to. Both come from the same runs, so a reader can never be told "runs dry" and "you have enough accounts" on adjacent lines.
The parenthetical is the actionable half and is present exactly when there is something to act on: a fleet already sitting on the smallest count that holds gets the count and nothing after it. The gap before it is two spaces, matching the dry moments in the block above, which a reader scans down the same column.
An unmeasured count is Unreadable and never NoQuantity. Every fleet has a smallest size that holds -- supply is linear in the seat count and burn is not a function of the fleet -- so the number exists and what failed was the measuring. NoQuantity would say there is no such number and stop a reader looking for the history that produces it.
A fleet with no usable accounts gets no line at all. "0 usable, ? needed" is a sentence about a fleet the rotation cannot reach, and the basis line above it already carries how many accounts there are and why none of them counted.
func RunwayBurn ¶ added in v0.7.0
RunwayBurn is a measured consumption rate, in percentage points per hour.
Low is what is printed and High is not: the upper bound is what a claim of "holds" had to survive, so it belongs to the verdict cell rather than to this one, and printing an interval in a column that is meant to be added up would make the column unaddable.
A band that cleared no gate is Unreadable and never 0.0. A measured zero, on the other hand, IS a reading -- the account was up, was polled, and did not burn -- and one live login at a time means most per-account rows carry one.
func RunwayCreditBasis ¶ added in v0.10.0
func RunwayCreditBasis(c forecast.CreditFleet) string
RunwayCreditBasis is what the credit row was measured from, as a sentence: the money, the span it was spent over, and how many readings carried it.
The window axes have had a basis line since they existed and the credit row has never had one, which was survivable only while no credit rate had ever been measured. The first one that was is the reason this exists: a dry date a decade out, correctly computed, from two cents. A reader cannot weigh that from the date, and the row has room for the one sentence that lets them.
It is empty for a refused figure, and the caller prints nothing rather than a sentence about a measurement that did not happen. There is no singular arm for the reading count because minSamples is three and creditSpend refuses below it, so "1 reading" is a state no figure reaching here can be in.
func RunwayCreditBurn ¶ added in v0.7.0
func RunwayCreditBurn(c forecast.CreditFleet) string
RunwayCreditBurn is the fleet's paid spend, in the currency's major unit per hour with the code beside it. Money's own width, because the unit is money; the code, because amounts in two currencies do not add and a bare figure invites a reader to add them anyway. creditRate is where the width is decided, and why it is not always two decimals.
A figure that could not be assembled is Unreadable, never zero. Every way it can fail -- mixed currencies, an uncapped account that is spending, no measured spend at all -- is a reason to say nothing rather than to report a fleet spending nothing, which would lengthen a runway made of money.
func RunwayCreditReplenish ¶ added in v0.7.0
func RunwayCreditReplenish() string
RunwayCreditReplenish is the credit row's replenishment cell, and it is a function taking nothing because the answer never varies: the endpoint reports no renewal boundary for paid usage, so there is no quantity here to read. That is NoQuantity and not Unreadable -- a reader told "?" would go looking for a renewal rate that does not exist.
func RunwayCreditVerdict ¶ added in v0.7.0
RunwayCreditVerdict is when the fleet's paid balance reaches zero, or Unreadable when the figure was refused.
It means something different from the two window rows above it and the command says so in prose beside the block: those ask whether resets replenish faster than the fleet spends, and this is a balance divided by a rate with nothing coming back.
func RunwayEmpty ¶ added in v0.7.0
RunwayEmpty is when the simulation first found one account out.
"now" comes first, ahead of any recorded moment, because it is a fact about this minute rather than a projection: an account that is out already must not be rendered as a date the reader could decide to wait for.
An account the run never found out is Unreadable. The run declining to empty an account is not the run promising it survives -- the axis may simply have held, or the band may have decided nothing.
func RunwayLeft ¶ added in v0.7.0
RunwayLeft is how much of an account's binding window is left, in percentage points and bare. No percent sign: the column is headed LEFT, it is summed into the fleet's points on the line above the table, and a percentage there would be read against the wrong window -- the one the account is REPORTED on elsewhere is not always this one.
func RunwayLine ¶ added in v0.7.0
RunwayLine is the one-line summary `ccdad status`, `ccdad list` and the dashboard share, so one wording is spelled once rather than three times.
It returns "" when there is nothing to say, and that empty string is load bearing: it is how all three callers know not to print a line at all, which is what keeps the dashboard's byte-compared golden fixtures from moving on a machine with no history behind it. A fleet with no basis gets no line, not a line saying it holds -- a promise resting on no reading is the one output this whole measurement exists to refuse.
The line carries VERDICTS, not rates. A rate is per axis, two of them do not fit a line that also has to carry the answer, and the number a dashboard owes a reader is when rather than how fast. It also carries no percentage, which is not a style choice: `ccdad status`'s human output is asserted to contain no "0%", "20%", "30m", "ahead" or "five_hour" anywhere, because each is a figure belonging to a window its table is not reporting.
The fleet run -- both axes burning at once -- appears only when it CONTRADICTS the two axes, which it can: it burns more windows and has more ways to end, so it can run dry, or run out of agreement between its two bands, while each axis alone holds. Printing it on every line would put a third verdict on a summary that already carries two and that agrees with them on every ordinary fleet; leaving it out when it disagrees would let "holds on both axes" stand over a fleet the arithmetic says empties.
A fleet that cannot hold also carries how many accounts would -- see RunwayNeedSegment for why only that fleet does.
func RunwayNeedSegment ¶ added in v0.7.0
RunwayNeedSegment is the seat count as one clause of RunwayLine, and it is carried only by a fleet that is SHORT.
A fleet that holds already has its answer in the word "holds", and the slack it has on top of that is a block-level figure rather than a dashboard one: the summary line is read at a glance beside Daemon:, Active: and Mode:, and a clause spent on good news is a clause the short case needed. The full form, spare count and all, is in RunwayAccounts.
The parenthetical here is one space, not the two RunwayAccounts uses. The clauses of this line are already held apart by their own separator, and a second wide gap inside one of them would read as a third clause.
RunwayLine's both-axes-hold branch does not call this, and it does not need to: a fleet whose runs all hold was answered by a search counting downward, so its count is at most its usable seats. A fleet that claimed both -- holding and short -- would be a contradiction the run cannot produce, and printing both halves of it on one line is not an improvement on printing one.
func RunwayReplenish ¶ added in v0.7.0
RunwayReplenish is what an axis gives back, in percentage points per hour. It always exists for a window axis: an axis with no accounts replenishes at zero, which is a true statement about an empty fleet rather than a reading nobody could take.
func RunwayRowCells ¶ added in v0.7.0
func RunwayRowCells(r forecast.AccountRow) (window, left, burn string)
RunwayRowCells is one account row's three weekly cells -- the window its points are counted on, the room left in it, and this account's own measured burn -- rendered together because they stand or fall together.
An account whose response carried no weekly window at all gets NoQuantity in all three and not Unreadable. Nothing failed to be read: the account was read, and this quantity does not exist for it. Borrowing its five-hour window instead would put a five-hour room and a five-hour rate into a column that is summed into the weekly axis above it, and those are two different quantities.
func RunwayVerdict ¶ added in v0.7.0
RunwayVerdict is an axis's answer as a cell: whether the fleet holds at the measured rate, and when it does not, the moment it empties.
An undecided axis renders Unreadable rather than either answer. The two runs of the band disagreeing means the evidence does not carry a claim, and both "holds" and a date would be claims.
func RunwayWrap ¶ added in v0.8.0
RunwayWrap folds the runway line onto width display columns, breaking only at its own separators and hanging every line after the first under the first clause.
A width of zero means the caller does not know one -- a pipe, a redirect, the buffer a test renders into -- and returns the line exactly as it was joined, byte for byte. That is the case every non-terminal writer takes, and it is what keeps this function out of the way of everything that reads the output as data.
The width arrives as a PARAMETER for the reason the zone does: nothing in this package may read the environment, and the terminal is environment. The caller nearest the reader measures it.
Clauses are atomic. A clause wider than the room gets its own line and is allowed to overflow rather than be cut, because this line ends in an absolute moment and a span: `2026-08-26 08:1` reads as a shorter date, not as a line that did not fit. The dashboard cuts because a page has a right edge it cannot spend; a scrollback has one it can. That is the whole of why these two renderers of one wording answer this differently, and it is not drift.
Every width here is a display column count. The separator is U+00B7 -- one column, two bytes -- so a byte count is wrong by the number of separators on the line, which is the number that grows as the line gets longer.
func ThresholdsFor ¶
func ThresholdsFor(cfg config.Config, now time.Time, plan strategy.Plan, planErr error) ( resolve func(uuid string) strategy.Thresholds, notices []string)
ThresholdsFor is internal/cli's thresholdsFrom with its notices RETURNED rather than written to a cobra command, so a caller with no command can use it. Package cli's own wrapper prints them and is otherwise unchanged.
The plan is read only when hover is on; with hover off it is ignored entirely, including its error.
func Timestamp ¶ added in v0.7.0
Timestamp is the one absolute-time rendering in this repository, and the zone is always in it. The two human-facing absolute formats that came before it carry neither a date nor a zone: internal/cli/hover.go's clock is "15:04", and internal/switcher/evaluate.go's Explain uses time.Kitchen. Both are fine for a moment inside the hour and useless for a runway that names one days out. Every remaining .Format in the tree is RFC 3339 or the daemon log's millisecond variant of it, which are machine formats and not an answer here. It lives in internal/view so the runway command, status, list and the dashboard spell one layout once rather than four times.
The zone is not optional, and it is not read here. The arithmetic that produces these moments must not touch the environment, so the location arrives as a parameter. A nil location falls back to UTC rather than to time.Local: a caller that passed none has not told us its zone, and time.Local would print a confidently wrong hour on any machine whose TZ is not the reader's -- including CI, where nothing sets it.
func UpdateLine ¶ added in v0.9.0
UpdateLine is the release line `ccdad status` prints under the daemon line and the terminal dashboard prints under its liveness block.
The daemon publishes what it SAW -- a version string -- and never a verdict, so the comparison happens here, against the version of the binary doing the reading. That is not a preference: upgrading replaces the binary while the old daemon keeps publishing, so a boolean computed by a 0.6.1 daemon would tell a 0.7.0 CLI to upgrade to what it is already running.
It is SILENT -- ok false -- for every reading it cannot turn into that sentence: no published document, nothing recorded, a recorded release that does not parse, a running version that does not parse (every `dev` build, so every build a developer makes), or a release that is not newer. A line that says nothing useful under a dashboard people read every day is worse than no line.
func WindowHeader ¶ added in v0.11.0
func WindowHeader(n usage.WindowName) string
WindowHeader is the short name a column carries.
The wire key stays the vocabulary -- it is what `ccdad config` and `--json` use -- and the legend under the table maps one to the other, so shortening here costs a reader nothing they cannot look up two lines down.
func WrapLabeled ¶ added in v0.8.0
WrapLabeled folds one line of the labelled block -- Daemon:, Active:, Hover:, Manual:, Mode: -- onto width display columns, breaking at spaces and hanging every line after the first under the value.
Measured on an 80-column terminal against a live fleet: Mode: is 124 display columns in recovery and Hover: is 100 whenever hover is on, so the terminal folded both wherever its own right edge fell -- mid-word, mid-clause, sometimes inside a quoted command a reader was meant to type.
It is a SEPARATE function from RunwayWrap, and the difference is not duplication. These lines are prose and break at spaces; the runway line is a row of values whose spaces are inside them, and a break at the one in `2026-08-26 08:19 KST` would produce a date that is not a date. Each knows where its own line may be cut, and neither may be pointed at the other's. What they share is the hanging alignment, which is `hang` below.
The label is found rather than passed, because these lines arrive with it already spelled: the block's contract is a name, a colon, and padding to nine columns, and that is what this looks for. A line with no colon has no label and no indent, which is the honest rendering of a line this block did not produce.
A width of zero -- every writer that is not a terminal -- returns the line exactly as its builder spelled it, and so does a terminal too narrow to hold the label, where there is no room to hang anything in.
Types ¶
type CellState ¶ added in v0.11.0
type CellState int
CellState is a cell's verdict about its own window.
type Columns ¶ added in v0.11.0
type Columns struct {
Windows []WindowColumn
Resets []ResetColumn
}
Columns is the whole quota block: the window columns and the reset columns they point into.
func ColumnsOf ¶ added in v0.11.0
ColumnsOf builds the block for a set of rows.
MEMBERSHIP is the union, over the visible rows, of every window each row actually carries. That is exactly the set `ccdad status --json` has published since it was written -- it walks the same windows and skips the absent ones -- so the human tables gain no new source here. They stop a derivation that threw away all but one of a set they already had.
cinder_cove can never appear and needs no filter: it is left out of the snapshot's own window list on purpose, because its reset is an EXPIRY rather than a rollover, so a countdown under a header meaning "rolls over in" would be counting down to a deletion.
func ColumnsOfNames ¶ added in v0.11.0
func ColumnsOfNames(names []usage.WindowName) Columns
ColumnsOfNames is ColumnsOf for a caller that already knows which windows it is describing and has no rows to derive them from.
`ccdad hover status` is that caller: its table comes from a ranking pass rather than from a cache read, and loading the cache a second time to rediscover a set it is already holding would be two reads that agree until the day one of them moves. It goes through the same order, the same headers and the same uniqueness passes, so the column a reader sees here is the column they saw on the other three surfaces.
It builds no reset columns: this caller has no rollovers to group, and a countdown it invented would be a second answer to a question `ccdad status` already answers.
func (Columns) Headers ¶ added in v0.11.0
Headers is the quota block's header row: one per window, then one per rollover. Both CLI tables and the dashboard call this rather than each assembling the same slice, which is what stops one of them growing a column the others do not have.
func (Columns) Legend ¶ added in v0.11.0
Legend maps every header back to the wire key it stands for.
It is the only place a human table still shows the key `ccdad config` takes a threshold on, which is what a full-name window column used to buy -- at the price of being one column naming one window per row.
func (Columns) Names ¶ added in v0.11.0
func (c Columns) Names() []usage.WindowName
Names is every window column's wire key, in column order.
func (Columns) Unranked ¶ added in v0.11.0
func (c Columns) Unranked() []usage.WindowName
Unranked is the columns the engine does not bind on.
func (Columns) UnrankedNote ¶ added in v0.11.0
UnrankedNote is the sentence for a column carrying real quota nothing switches away from, or empty when every column ranks.
It names the hand edit and NOT `ccdad config set`, deliberately: the setter refuses exactly these names while the loader carries them, so advice to run it would send the reader into the binary's own refusal.
type Exec ¶
Exec runs one ccdad command through a FRESH cobra root and reports what it wrote and what it exited with. It is a function value declared in this leaf package because internal/cli must import internal/tui to register a command, so internal/tui must never import internal/cli. internal/mcpsrv takes the identical seam.
type ResetColumn ¶ added in v0.11.0
type ResetColumn struct {
Header string
Windows []usage.WindowName
}
ResetColumn is one rollover, shared by every window that rolls with it.
type Row ¶
type Row struct {
Account store.Account
Active bool
Entry usage.Entry
HasEntry bool
Headroom strategy.Headroom
// Thresholds is the bundle this row was MEASURED against, kept so a cell can
// be coloured against the same numbers.
//
// It is resolved once in Rows and handed to HeadroomOrCredit from this
// field, so the bundle a cell reads and the bundle the row was ranked on
// are one object by construction rather than two calls that agree until the
// day one of them moves. Under hover that matters twice over: the table is
// derived per account and per window, so a second resolution could hand a
// cell a number no part of this row was measured with.
Thresholds strategy.Thresholds
Pace map[usage.WindowName]usage.Pace
Engine daemon.AccountStatus
}
Row is one account with everything the dashboard knows about it, from each field's one authoritative source.
func Rows ¶
func Rows(accounts []store.Account, cache *usage.Cache, active store.Account, hasActive bool, now time.Time, thresholds func(uuid string) strategy.Thresholds) []Row
Rows pairs every account with its cached reading.
`list` builds its rows through this too, and that is what "`ccdad list` and `ccdad status --json` can never disagree" actually rests on: one cache, read one way, into one shape. Two commands each deriving headroom for themselves would agree until the day one of them was changed.
Engine state is deliberately NOT filled in here. It comes from status.json, which is the daemon's own document and no part of what `list` reports.
func (Row) CarriedWindows ¶ added in v0.11.0
func (r Row) CarriedWindows() []usage.NamedWindow
CarriedWindows is every window this row's reading actually carries, in wire order, plus the credit meter when it reported a percentage.
The Present filter is load-bearing rather than tidiness. Snapshot's fixed Claude keys are listed unconditionally, so an unfiltered walk hands every Claude fleet five columns with three of them null on every row forever.
func (Row) CellState ¶ added in v0.11.0
func (r Row) CellState(n usage.WindowName) CellState
CellState is the verdict that colours one cell.
EMPTY IS CHECKED FIRST, ahead of the band, and that order is the whole of this function. Under hover a threshold is an unclamped PACE TARGET, so a window far enough through its own cycle with nothing left in it reports POSITIVE slack -- measured on a live fleet at +17, past WarnBand -- and a band consulted first paints a spent week the colour of a healthy one. Over is reserved for pct >= 100, which is the one verdict the cell's own text already states, so no arm here can contradict what the reader is looking at.
The band reads THIS window's threshold and no other. Headroom.Slack is one window per account; a cell is one window per cell, and feeding it the account's number would colour a cell from a window it is not about.
func (Row) Cells ¶ added in v0.11.0
Cells is one row's quota block, in Headers' own order and always the same length, so a caller can append it between its own fixed columns.
func (Row) CreditLine ¶ added in v0.11.0
CreditLine is the money sentence for a seat metered in credits, which no percentage column can carry.
A balance beats a percentage here: "795.23/2000.00 used, 1204.77 left (USD)" is what a person deciding whether to top up needs, and 40% is not.
func (Row) ListLabel ¶
ListLabel is both the address and the handle, which is NOT Account.Label(): that one returns the alias alone, and a listing is where a user learns which alias belongs to which address.
func (Row) Marker ¶
Marker is the active-row marker: the character `status` and `list` both already print in front of the IDX column.
func (Row) Reported ¶
func (r Row) Reported() (usage.NamedWindow, bool)
Reported resolves ReportedName to the window itself, together with when it rolls over. It is what the USED, WINDOW, RESETS IN and PACE columns all read, so they always describe the same window.
The Known check is redundant TODAY and is kept deliberately: with no window reporting a utilization, strategy leaves both names as the empty WindowName and the loop below matches nothing anyway. A mutation removing it survives for exactly that reason. It stays because the alternative is for this function's correctness to rest on an invariant of another package's zero value.
func (Row) ReportedName ¶
func (r Row) ReportedName() usage.WindowName
ReportedName is the window this account is REPORTED against, which is not always the one it is ordered on.
A tripped WEEKLY cap wins, because it is the one that will not come back for days: an account whose five-hour window rolls over in eight minutes is still unusable until Friday, and naming the five-hour window would tell the user to wait eight minutes for it. Ordering still runs on Headroom.Slack, which is the tightest window whichever family it belongs to, so this rule moves no account in the ordinary order. It is not inert in RECOVERY order: what an account has to wait out is the weekly floor, so the same field decides whether it counts as returning inside the horizon.
func (Row) ResetCell ¶ added in v0.11.0
func (r Row) ResetCell(c ResetColumn, now time.Time) string
ResetCell is one countdown, for the group a column points into.
func (Row) StatusFlags ¶
StatusFlags is the suffix `ccdad status` prints after the age column. It is NOT `ccdad list`'s: that one joins primary and disabled, because a listing is where an account is chosen and an account can carry both flags at once.
func (Row) StatusLabel ¶
func (Row) TypeLabel ¶
TypeLabel is what the TYPE column says about an account.
It now has three callers rather than one, and the reason is the reason it stopped being derivable from Kind alone. Every ChatGPT plan is a subscription, so a codex row rendered from Kind would say "subscription" -- true, and useless: it would be the word on every codex row and on most of the Claude rows beside them, distinguishing nothing. What a reader needs in that column is which side of the machine the row belongs to, because that is what decides which command moves it.
So `list`, `status` and the dashboard all call this rather than formatting Kind themselves. Three renderers formatting one value three ways is the exact "one value, two spellings" failure package view exists to remove -- and here it would have shown as two tables calling an account a subscription while the third called it codex.
func (Row) WindowCell ¶ added in v0.11.0
func (r Row) WindowCell(n usage.WindowName) string
WindowCell is one quota cell: the percentage USED.
Used and not left, so that 100% means the same thing in every cell of the table and the eye can scan a row for the number that stops it. The polarity is stated once, here, and the header row says nothing about it.
func (Row) WindowPct ¶ added in v0.11.0
func (r Row) WindowPct(n usage.WindowName) (float64, WindowState)
WindowPct is this row's utilization of one window, and why there is no number when there is none.
func (Row) WindowReset ¶ added in v0.11.0
WindowReset is when one window rolls over.
func (Row) WindowSpent ¶ added in v0.11.0
func (r Row) WindowSpent(n usage.WindowName) (spent, known bool)
WindowSpent is whether one window has nothing left in it.
It is spelled here rather than delegated because strategy carries no window-level predicate to delegate to: OutOfQuota is the ACCOUNT-level one, and the two stopped agreeing the moment a cap scoped to one model family could be gone while the account went on serving every other model.
type Snapshot ¶
type Snapshot struct {
Now time.Time
Rows []Row
Report daemon.Report
ActiveLabel string // "work@example.com (work)", or "none of the managed accounts"
// CodexServingLabel is the account ccdad's codex proxy serves new threads
// from, or "" when there is no pointer or it names no stored account.
//
// EMPTY IS LOAD-BEARING. It is what keeps every surface rendering the exact
// bytes it rendered before codex existed on a machine that has no codex
// account -- seven byte-compared dashboard pages among them.
CodexServingLabel string
// CodexServingUUID is the same account's key, for the --json payloads. A
// label is for a person and a uuid is what a script keys on, and deriving
// one from the other at the payload builder would be a second lookup of a
// pointer this snapshot has already read.
CodexServingUUID string
Strategy string // config.Config.Strategy.String(), as CONFIGURED -- see StrategyLabel
Hover bool // config.Config.Hover
// Manual is config.Config.Manual. It is carried beside Hover rather than
// folded into the mode line because the two are different questions: Hover
// says where the numbers came from, Manual says whether ccdad will act on
// them. A fleet in manual mode with a healthy ranking looks exactly like a
// broken engine unless the dashboard says which it is.
Manual bool
Mode strategy.Mode
HasMode bool
Version string // buildinfo.String()'s first field, or a test constant
Notices []string // everything cli would have written to stderr
// Forecast is the measured burn and what it implies, and HasForecast is
// whether one could be produced at all.
//
// The pair is a tri-state and not a nilable pointer, for the reason the
// fields above it are: a dashboard reads this struct and must never be able
// to dereference its way into a panic on a machine that has been recording
// for ten minutes. HasForecast false is "no measurement", never "a fleet
// burning nothing" -- the zero Fleet's verdicts are all VerdictUnknown, so
// a renderer that ignored the flag would still print no promise.
//
// Package cli computes it, as it computes everything else here, so the same
// value reaches the dashboard and the command line and no number is derived
// in two places.
Forecast forecast.Fleet
HasForecast bool
}
Snapshot is one complete read of the documents a dashboard renders. Package cli builds it — it owns the attribution probe and the notice stream — and package tui only reads it, so no number is derived in two places.
func (Snapshot) ActiveLine ¶ added in v0.11.0
ActiveLine is this snapshot's.
func (Snapshot) StrategyLabel ¶ added in v0.7.0
StrategyLabel is the strategy in FORCE, which under hover is not the one in the file.
Hover derives its own: strategy.Options' withHover pass overrides the key with headroom, because a window close to its reset already carries a high threshold and ordering by reset instant on top of that would rank on a quantity none of hover's numbers came from. config.HoverOverrides answers true for the key and `ccdad config list` marks it, so a header naming the file's value was the one surface left spelling a setting nothing applies -- which reads to a user as hover not being on at all.
Strategy itself keeps the configured value rather than being overwritten, because the terminal dashboard's strategy picker marks its current entry from it. Setting the key while hover is on is a legitimate "for later"; it is only naming it as the one in force that is false.
type WindowColumn ¶ added in v0.11.0
type WindowColumn struct {
// Name is the wire key. It is the key `ccdad config` takes a per-window
// threshold on and the key `--json` files the window under, so a reader who
// moves between the table and either of those reads one vocabulary.
Name usage.WindowName
// Header is short, and unique within its Columns by construction.
Header string
// Reset indexes Columns.Resets, or -1 when no visible row reported a
// rollover for this window.
Reset int
// Ranked is whether the engine binds on this window without being asked.
// A window it does not rank can sit at 100% with nothing switching away
// from it, and a column that did not say so would be a lie by omission.
Ranked bool
}
WindowColumn is one quota column.
type WindowState ¶ added in v0.11.0
type WindowState int
WindowState is why a cell says what it says. The three are kept apart because they are three different facts and one of them is a bug if it is guessed.
const ( // WindowAbsent: the reading does not carry this window at all. Rendered // "-". It is a statement about the ACCOUNT -- a Codex seat has no // five-hour window and never will -- and it is only ever said about a // reading somebody actually took. WindowAbsent WindowState = iota // WindowUnreadable: nothing was read, or the window was carried and // reported no utilization. Rendered Unreadable. // // Never "-" and never "0%". An account nobody could read is not an account // with a fresh window, and cswap's engine parked itself permanently on // exactly that confusion. Present-with-null is a real shape on the wire -- // a freshly reset window reports {"utilization":null,"resets_at":null} and // still HAS the window -- so the two absences are not the same absence. WindowUnreadable // WindowRead: a utilization came back. WindowRead )