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 ¶
func Build ¶
func Build(now time.Time, latest quota.Reading, haveLatest bool, quotaErr string, hist []quota.Reading, sc *Scanner) *model.Usage
Build assembles the Quota tab's data at now. latest is the newest official reading (live, or the last recorded one when quotaErr says aiquota could not be read); hist is every recorded reading, oldest first.
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.
func NewEngine ¶
NewEngine reads transcripts under claudeDir/projects, caches sums in cacheDir and records readings in configDir.
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.