Documentation
¶
Overview ¶
Package usage turns the transcripts' token counts into the Quota tab's data.
A transcript is read once: the scanner remembers, per file, how far it read, and keeps only per-bucket sums (10 minutes, per model family), cached under the user cache directory, so a restart reads what was appended and not gigabytes. Only numbers are decoded: the struct has no field for message content.
Index ¶
Constants ¶
const BucketSec = 600
BucketSec is the resolution of the kept sums.
const Keep = 35 * 24 * time.Hour
Keep is how far back sums are kept: four 7 day windows and a week of margin for the alignment on the reset.
const ScanEvery = time.Minute
ScanEvery is how often transcripts are scanned for new tokens.
Variables ¶
var Families = model.Families
Families are the stack order of the charts.
Functions ¶
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine keeps the Quota tab's data current: it scans transcripts every ScanEvery, reads aiquota at most every quota.MinInterval, and records each reading with the account it belongs to.
func NewEngine ¶
NewEngine reads transcripts under claudeDir/projects, caches sums in cacheDir and records readings in configDir. The signed-in account is read from the .claude.json next to claudeDir.
type Input ¶ added in v0.8.0
type Input struct {
Now time.Time
// Live is the last successful aiquota reading, one per account, tagged; empty
// when aiquota has not been read (or could not be).
Live []quota.Reading
// Hist is every recorded reading (live ones included), oldest first.
Hist []quota.Reading
// QuotaErr is why aiquota could not be read.
QuotaErr string
// Active is the key of the account Claude Code is signed in to, "" unknown.
Active string
}
Input is everything Build needs besides the transcripts.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner holds the per-file offsets and the per-bucket sums.
func NewScanner ¶
NewScanner reads transcripts under root and keeps its cache in cacheFile ("" keeps none). A cache that cannot be read is ignored: it is rebuilt.
func (*Scanner) Accounts ¶ added in v0.8.0
Accounts is the keys of the accounts that have tokens, and whether any tokens are unattributed.
func (*Scanner) Buckets ¶
func (s *Scanner) Buckets(start, step int64, n int, w Which, acct string) (out, cacheRead [][]float64)
Buckets returns n buckets of step seconds from start: out[layer][i] and cacheRead[layer][i], one layer per family, and for Every one more for the unattributed tokens. step is a multiple of BucketSec.