usage

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const BucketSec = 600

BucketSec is the resolution of the kept sums.

View Source
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.

View Source
const ScanEvery = time.Minute

ScanEvery is how often transcripts are scanned for new tokens.

Variables

View Source
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 Counts

type Counts struct {
	Out       int64 `json:"o,omitempty"`
	CacheRead int64 `json:"c,omitempty"`
}

Counts is the tokens of one family in one bucket.

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

func NewEngine(claudeDir, cacheDir, configDir string, run quota.Runner) *Engine

NewEngine reads transcripts under claudeDir/projects, caches sums in cacheDir and records readings in configDir.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context)

Run steps now and then every ScanEvery until ctx ends.

func (*Engine) Step

func (e *Engine) Step(ctx context.Context, now time.Time)

Step does one pass at now.

func (*Engine) View

func (e *Engine) View() *model.Usage

View is the latest data, nil before the first pass ended.

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner holds the per-file offsets and the per-bucket sums.

func NewScanner

func NewScanner(root, cacheFile string) *Scanner

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) Buckets

func (s *Scanner) Buckets(start, step int64, n int) (out, cacheRead [][]float64)

Buckets returns n buckets of step seconds from start, per family and kind: out[family][i] and cacheRead[family][i]. step is a multiple of BucketSec.

func (*Scanner) Refresh

func (s *Scanner) Refresh(now time.Time) Stats

Refresh scans what changed since the last pass and drops sums older than Keep. It returns what it did.

type Source

type Source struct {
	Inner interface{ Snapshot() model.Snapshot }
	Eng   *Engine
}

Source adds the engine's view to the snapshots of an inner source.

func (Source) Snapshot

func (s Source) Snapshot() model.Snapshot

Snapshot is the inner snapshot with the Usage view attached.

type Stats

type Stats struct {
	Files, Scanned int
	Bytes          int64
	Lines, Counted int
	Skipped        int // lines over maxLine
	Bad            int // usage lines that did not decode
}

Stats says what a Refresh did, for tests and for the cold-scan measurement.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL