Documentation
¶
Overview ¶
Package spend keeps what the agents in the panes have spent, and how close they are to the limits they run under.
Two kinds of people run agents, and they want different numbers. Somebody paying per token wants money; somebody on a subscription pays the same whatever happens and is stopped by a usage window instead, so for them the headline is how much of the window is used and when it resets. Both numbers come from the agents themselves -- Flockdeck's own chat client counts every call it makes, and Claude Code hands its status line the session's cost and the subscription's windows -- and nothing here is fetched from anywhere: the figures arrive over the loopback hook server and never leave the machine.
Nothing here is billed truth. A price is Flockdeck's table or the agent's own list price, and the interface marks every figure derived from one as an estimate. Tokens are counted exactly and carry no mark.
Index ¶
Constants ¶
const ( WarnAt = 80 FullAt = 95 )
Thresholds at which a window is worth a colour: amber at WarnAt, red at FullAt. They are fixed until the setting for them exists.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Book ¶
type Book struct {
// contains filtered or unexported fields
}
Book is what every pane has spent in its current conversation, and the latest reading of every window, held in memory.
It is safe for concurrent use: reports arrive on the hook server's goroutines and are read back on the workspace's.
type Cost ¶
type Cost struct {
USD float64 `json:"usd,omitempty"`
// Known is false when some of the tokens had no price, so USD is a floor.
Known bool `json:"known,omitempty"`
// Source is "table" for tokens priced from Flockdeck's own table, and
// "agent" for a figure the agent reported about itself at its own list
// prices -- Claude Code's session cost is one.
Source string `json:"source,omitempty"`
// Checked is the date the price table was read from the vendor's page, for
// a "table" cost.
Checked string `json:"checked,omitempty"`
}
Cost is money, and where the figure came from.
type PaneView ¶
type PaneView struct {
// USD is the session's cost in dollars, an estimate: Source says whose.
USD float64 `json:"usd,omitempty"`
Unpriced bool `json:"unpriced,omitempty"`
Source string `json:"source,omitempty"`
Checked string `json:"checked,omitempty"`
// Tokens is everything read and written, and the four after it the parts
// the tooltip names.
Tokens int64 `json:"tokens,omitempty"`
In int64 `json:"in,omitempty"`
Out int64 `json:"out,omitempty"`
CacheRead int64 `json:"cacheRead,omitempty"`
Reasoning int64 `json:"reasoning,omitempty"`
Windows []WindowView `json:"windows,omitempty"`
}
PaneView is what the pane header draws: the session's spend, and every window the pane draws on, tightest first. Its figures are rounded to what the header shows, so that a reading which changes nothing on screen does not make a new state for every window to be sent.
type Report ¶
type Report struct {
// Pane is the pane's own id, which is what every lifecycle event is
// reported against as well.
Pane string `json:"session"`
// Conversation is the agent's own id for the conversation, where it says.
// A new one starts the pane's session figures again, as /clear does in
// Claude Code.
Conversation string `json:"conversation,omitempty"`
Model string `json:"model,omitempty"`
// Account names the login the pane draws on, reported even before any
// window is, so the windows another pane reports for it can be shown here.
Account string `json:"account,omitempty"`
Tokens Tokens `json:"tokens"`
Cost Cost `json:"cost"`
// Cumulative says Tokens and Cost are the conversation's running totals as
// the agent counts them, which replace what was known rather than adding
// to it. Otherwise they are one call's, and are added up here.
Cumulative bool `json:"cumulative,omitempty"`
Windows []Window `json:"windows,omitempty"`
}
Report is what a pane's agent says it has spent, sent over the hook server.
type Tokens ¶
type Tokens struct {
In int64 `json:"in,omitempty"`
Out int64 `json:"out,omitempty"`
CacheRead int64 `json:"cacheRead,omitempty"`
CacheWrite5m int64 `json:"cacheWrite5m,omitempty"`
CacheWrite1h int64 `json:"cacheWrite1h,omitempty"`
Reasoning int64 `json:"reasoning,omitempty"`
}
Tokens is what model calls read and wrote. Zero means none, not unknown.
type Window ¶
type Window struct {
// Account says whose limit it is, in terms that stay on this machine: the
// Claude Code configuration folder for a Claude login. A key itself is
// never used for this, hashed or otherwise.
Account string `json:"account"`
// Name is the window's own name, as the agent calls it: "five_hour",
// "seven_day".
Name string `json:"name"`
// Used is 0 to 100 when Percent, and otherwise a count against Limit.
Used float64 `json:"used"`
Limit float64 `json:"limit,omitempty"`
Percent bool `json:"percent,omitempty"`
// ResetsAt is when the window starts over. A reading past it describes a
// window that no longer exists.
ResetsAt time.Time `json:"resetsAt,omitzero"`
// Seen is when the reading arrived. It is set here, on arrival, rather
// than taken from the reporter.
Seen time.Time `json:"seen,omitzero"`
Source string `json:"source,omitempty"`
}
Window is one limit and how much of it is used.
A limit belongs to an account, not to a pane: five Claude panes on one login draw on one five-hour window, as claude.ai and other machines on that login do, so a reading from any of them describes all of them.
type WindowView ¶
type WindowView struct {
Name string `json:"name"`
// Pct is how much of it is used, to the whole percent.
Pct float64 `json:"pct"`
// ResetsAt and AsOf are Unix seconds; AsOf to the minute, since it is only
// ever said of a reading that is some minutes old.
ResetsAt int64 `json:"resetsAt,omitempty"`
AsOf int64 `json:"asOf,omitempty"`
Level string `json:"level,omitempty"`
}
WindowView is one window as the header draws it.