budget

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 10 Imported by: ? modules, 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 budget builds the REST budget view: how much of GitHub's REST quota is left, until when, and who spent it. agentscope reads and never spends: the only things read are the call ledger (a local file, ghbudget.ReadLedger) and, at most once per MinInterval per token and only when the ledger holds no fresher reading, GET /rate_limit, which GitHub does not count against the limit. No other endpoint is ever requested.

A token is read only to be sent in the Authorization header and fingerprinted; it is never kept, logged, or put in the view.

Index

Constants

View Source
const APIBase = "https://api.github.com"

APIBase is GitHub's REST root.

View Source
const MaxLedger = 1 << 20

MaxLedger bounds what is read of the ledger.

View Source
const MinInterval = 60 * time.Second

MinInterval is the least time between two GET /rate_limit of one token.

View Source
const RefreshEvery = 10 * time.Second

RefreshEvery is how often Run rebuilds the view. Reading the ledger is a local file read; the /rate_limit call it may trigger is bounded by MinInterval.

View Source
const Window = time.Hour

Window is how far back the ledger is attributed.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	LedgerPath string // default ghbudget.DefaultLedgerPath()
	TokenFile  string // default ghauth.DefaultPath()
	Base       string // default APIBase
	Client     *http.Client
	Now        func() time.Time
}

Config is where the engine reads. Zero values take the defaults.

type Engine

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

Engine builds the view.

func New

func New(cfg Config) *Engine

New returns an engine over cfg.

func (*Engine) View

func (e *Engine) View(ctx context.Context) *model.Budget

View reads the ledger and, when due, /rate_limit, and returns the view.

type Runner

type Runner struct {
	Eng *Engine
	// contains filtered or unexported fields
}

Runner keeps the latest view of an Engine.

func (*Runner) Latest

func (r *Runner) Latest() *model.Budget

Latest is the last view, nil before the first step ended.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context)

Run steps now and then every RefreshEvery until ctx ends.

func (*Runner) Step

func (r *Runner) Step(ctx context.Context)

Step rebuilds the view now.

type Source

type Source struct {
	Inner interface{ Snapshot() model.Snapshot }
	Run   *Runner
}

Source adds the latest budget view to the snapshots of an inner source.

func (Source) Snapshot

func (s Source) Snapshot() model.Snapshot

Snapshot is the inner snapshot with the Budget view attached.

Jump to

Keyboard shortcuts

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