usage

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package usage is the ledger `logos usage` reads: what each context pack cost against what it drew from, and each time a recorded dead end was handed back to an agent about to retry it.

Every number here is a receipt, never an estimate of something Logos cannot see. It cannot see a host's API usage, so "tokens saved" is a pack's size against its own uncut candidates, both measured by contextpack on the same estimate. It cannot tell whether an agent heeded a dead end, so the count is of dead ends returned, not of mistakes avoided.

JSONL in the vault, one file per month, for the reasons internal/activity gives: a person can read it with grep, and it survives the index being deleted. Totals kept only in SQLite would be the fifth time a durable record silently lived in the cache. Unlike the activity log it holds no prompt and no tool output — a timestamp, a project name and counts — so it is kept, not aged out: a running total that forgets its first month is not a total.

Index

Constants

View Source
const (
	KindPack    = "pack"     // a context pack was handed to an agent
	KindDeadEnd = "dead-end" // a recorded dead end was handed back before a retry
)

Event kinds.

View Source
const Dir = "usage"

Dir is the vault subdirectory holding the ledger.

Variables

This section is empty.

Functions

func Record

func Record(vault string, e Event) error

Record appends one event.

Errors are returned, and a caller reports rather than swallows them: a ledger that silently stopped being written would show a total that looks complete and is not. They must not fail the pack or the check being recorded, which already did its job.

func RecordPack

func RecordPack(vault, via, project string, b contextpack.Budget) error

RecordPack records a rendered pack. Its headings and footer are counted on both sides, so the saving is exactly what the budget left out.

func Recording

func Recording(vault string) bool

Recording reports whether this vault's ledger takes new events. On unless someone said otherwise — it holds counts, never prompts or content — but everything Logos writes on its own has a switch, with `logos usage off` for the vault and LOGOS_USAGE=off for one process.

func SetRecording

func SetRecording(vault string, on bool) error

SetRecording turns the ledger on or off for this vault. What is already recorded is left alone either way; the files are the user's to delete.

Types

type Event

type Event struct {
	TS      int64  `json:"ts"`
	Kind    string `json:"kind"`
	Project string `json:"project,omitempty"`
	// Via is where it happened, "mcp:resume" or "cli:tried", so a total can be
	// traced back to the path that produced it.
	Via string `json:"via"`
	// Sent and Full are a pack's tokens as sent and as its candidates came to
	// uncut, the same headings and footer counted in both.
	Sent int `json:"sent,omitempty"`
	Full int `json:"full,omitempty"`
	// Rulings is how many recorded dead ends a dead-end event returned.
	Rulings int `json:"rulings,omitempty"`
}

Event is one line of the ledger.

func Read

func Read(vault string) ([]Event, int, error)

Read returns every event in the ledger, oldest first, and how many lines could not be read. A torn line costs that line, not the month — but the count is returned, because a total quietly missing lines is a total that is wrong without saying so.

type Totals

type Totals struct {
	Packs int
	Sent  int
	Full  int
	// DeadEndChecks is the number of checks that returned at least one recorded
	// dead end, and Rulings the dead ends they returned between them.
	DeadEndChecks int
	Rulings       int
	Since         int64
}

Totals is the ledger summed.

func Sum

func Sum(events []Event, project string) Totals

Sum totals the events for one project, or for all of them when project is "".

func (Totals) Saved

func (t Totals) Saved() int

Saved is what the packs' budgets left out, in tokens.

Jump to

Keyboard shortcuts

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