tokens

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToJSON

func ToJSON(u *Usage) string

ToJSON serializes token usage to JSON for database storage.

Types

type Usage

type Usage struct {
	OutputTokens      int64 `json:"total_output_tokens,omitempty"`
	PeakContextTokens int64 `json:"peak_context_tokens,omitempty"`
}

Usage holds token consumption data for a single review job. Stored as JSON in the review_jobs.token_usage column. Fields align with agentsview's token-use output.

func FetchForSession

func FetchForSession(
	ctx context.Context, sessionID string,
) (*Usage, error)

FetchForSession calls `agentsview token-use <sessionID>` to get token usage. Returns nil (no error) if agentsview is not installed or the session data is unavailable.

func ParseJSON

func ParseJSON(data string) *Usage

ParseJSON deserializes a token_usage JSON blob from the database. Returns nil for empty/null values.

func (Usage) FormatSummary

func (u Usage) FormatSummary() string

FormatSummary returns a compact human-readable summary like "118.0k ctx · 28.8k out". Returns empty string if no data.

Jump to

Keyboard shortcuts

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