quota

package
v0.10.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: 13 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 quota reads the official usage windows from `aiquota status -o json` and keeps a bounded, append-only history of them.

aiquota already shares one reading across processes and serves stale data while it is rate-limited, and keeps only its last reading; this package adds the history. It samples at most every MinInterval and never talks to a provider itself.

Index

Constants

View Source
const (
	LabelSession = "Session (5hr)"
	LabelWeek    = "Weekly (7 day)"
)

Labels aiquota gives the two windows that have a reset the charts align on.

View Source
const MinInterval = 5 * time.Minute

MinInterval is the shortest time between two readings.

View Source
const (
	RotateBytes = 4 << 20 // the history file is rotated past this size
)

Bounds on what is read and kept.

Variables

This section is empty.

Functions

func AccountKey added in v0.8.0

func AccountKey(id string) string

AccountKey is the stable, short key of an account id: the first 8 hex digits of its SHA-256. The id itself, and the e-mail, are never kept.

func Exec

func Exec(ctx context.Context) ([]byte, error)

Exec is the Runner that runs the aiquota binary on PATH, with fixed arguments and no shell.

func LabelKey added in v0.8.0

func LabelKey(label string) string

LabelKey is the key of an account known only by the label aiquota gave it.

func Tag added in v0.8.0

func Tag(rs []Reading, active string)

Tag sets the accounts' keys. active is the key of the account Claude Code is signed in to ("" when it could not be told, or changed during the reading): with a single account in the output it is that one; with several, each is known by its label alone, since nothing says which of them is the active one.

Types

type Reading

type Reading struct {
	At      int64    `json:"at"`
	Acct    string   `json:"acct,omitempty"`
	Label   string   `json:"lbl,omitempty"`
	Plan    string   `json:"plan,omitempty"`
	Windows []Window `json:"w"`
}

Reading is every window of one account at one instant (Unix seconds).

Acct is the account's stable key (see AccountKey, LabelKey); "" is a reading recorded before accounts were told apart, or taken when the account could not be told: its account is unknown and is never guessed.

func Parse

func Parse(b []byte) ([]Reading, error)

Parse decodes the output of `aiquota status -o json`: one Reading per account label, in order of appearance, their keys unset (see Tag). A window whose verdict is "n/a" is Available false: it is listed, never drawn as 0.

func (Reading) Find

func (r Reading) Find(label string) (Window, bool)

Find returns the window with the label.

type Runner

type Runner func(ctx context.Context) ([]byte, error)

Runner runs `aiquota status -o json` and returns its output.

type Store

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

Store is the history: JSON lines in dir/quota.jsonl, rotated to quota.jsonl.1 past RotateBytes (the older half of the history is the rotated file).

func NewStore

func NewStore(dir string) *Store

NewStore keeps the history in dir, which is created when first written.

func (*Store) Append

func (s *Store) Append(r Reading) error

Append adds one reading.

func (*Store) Load

func (s *Store) Load() (rs []Reading, bad int)

Load returns every reading kept, oldest first. A line that does not parse is skipped and counted: a torn write or a hand edit must not hide the rest.

type Window

type Window struct {
	Label     string  `json:"l"`
	Percent   float64 `json:"p,omitempty"`
	ResetsAt  int64   `json:"r,omitempty"`
	Available bool    `json:"a,omitempty"`
}

Window is one window of a reading.

Jump to

Keyboard shortcuts

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