usage

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 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 usage reads the tokens each ended turn spent, through the reader of the turn's agent, and stores them once.

Index

Constants

View Source
const (
	Window            = 30 * 24 * time.Hour
	Late              = time.Hour
	Batch             = 50
	MaxAttempts       = 5
	SourceTranscript  = "transcript"
	SourceUnavailable = "unavailable"
	KindTurnUsage     = "turn_usage" // Key = turn seq, Data = source
)

Variables

View Source
var ErrNoTranscript = errors.New("the transcript is gone")

Functions

This section is empty.

Types

type Reader

type Reader interface {
	Usage(ctx context.Context, t Turn) ([]usage.Model, error)
}

type Service

type Service struct {
	Store     Store
	ReaderFor func(kind string) Reader
	Clock     port.Clock
	// Log gets the first reader error of each run; nil drops it.
	Log func(format string, args ...any)
}

func (Service) Run

func (s Service) Run(ctx context.Context) (string, error)

Run reads the usage of up to Batch pending turns. A turn whose reader fails stays pending for the next run, and is unavailable once it failed MaxAttempts times.

type Store

type Store interface {
	Pending(ctx context.Context, endedSince time.Time, limit int) ([]Turn, error)
	SaveUsage(ctx context.Context, seq int64, rows []usage.Model, source string, at time.Time, evs ...port.Event) error
	Attempted(ctx context.Context, seq int64) error
}

type Turn

type Turn struct {
	Seq                                      int64
	PR                                       pr.Ref
	Kind                                     string
	AgentSession, Transcript, Home, Worktree string
	From, To                                 time.Time
	Attempts                                 int
}

Turn is an ended turn whose usage is not read yet, with its agent session's paths and the window its messages fall in.

Jump to

Keyboard shortcuts

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