Documentation
¶
Overview ¶
Package usage totals an agent session's token usage from its transcript.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CodexRollout ¶
type CodexRollout struct {
// contains filtered or unexported fields
}
CodexRollout follows a Codex session file (JSON lines) as it grows. Codex writes cumulative token_count events, so the latest one holds the totals.
func NewCodexRollout ¶
func NewCodexRollout(path string) *CodexRollout
NewCodexRollout follows the rollout file at path.
func (*CodexRollout) Limits ¶
func (c *CodexRollout) Limits() *proto.PlanLimits
Limits returns the plan limits the session last reported, if any.
func (*CodexRollout) Update ¶
func (c *CodexRollout) Update() (Tokens, error)
Update reads what was appended since the last call.
type History ¶ added in v0.1.9
type History struct {
// contains filtered or unexported fields
}
History follows the saved conversations of every agent it is asked about. Safe for concurrent use.
func (*History) ByAccount ¶ added in v0.2.2
func (h *History) ByAccount(home string, env func(string) string, now time.Time, loc *time.Location, others ...Root) proto.UsageHistory
ByAccount is Summary one entry per account rather than per agent, each with its last 24 hours and 30 days in buckets for charting, the hours and days starting where they do in loc. An account with nothing saved in the last 30 days is left out, as an agent is in Summary.
func (*History) Summary ¶ added in v0.1.9
func (h *History) Summary(home string, env func(string) string, now time.Time, others ...Root) proto.UsageHistory
Summary is what each agent used in each period, by model, as of now. home is the home directory whose agents' folders are read; env says where an agent was told to keep them instead (CLAUDE_CONFIG_DIR, CODEX_HOME); others are the agents' other accounts.
type Root ¶ added in v0.2.1
type Root struct {
Agent, Dir string
// Name is the account's, for ByAccount; "" is the agent's own.
Name string
}
Root is another of an agent's configuration folders: an account of its own (internal/accounts), whose conversations count as the agent's.
type Tokens ¶
type Tokens struct {
Input int `json:"input"` // uncached input tokens
CacheWrite int `json:"cache_write"` // input tokens written to the prompt cache
CacheRead int `json:"cache_read"` // input tokens read from the cache
Output int `json:"output"`
Context int `json:"context"` // tokens in the latest request's context
Model string `json:"model,omitempty"`
// CostUSD is the session's cost when the agent reports one; 0 otherwise
// (conch doesn't estimate prices).
CostUSD float64 `json:"cost_usd,omitempty"`
// ContextSize is the model's context window, when known.
ContextSize int `json:"context_size,omitempty"`
}
Tokens is a session's usage so far.
func OpenCodeSession ¶
OpenCodeSession reads a session's usage from OpenCode's sqlite store through the sqlite3 command.
type Transcript ¶
type Transcript struct {
// contains filtered or unexported fields
}
Transcript follows a Claude Code transcript (JSON lines) as it grows. A response is written as several lines sharing one message id and carrying its usage so far, so usage is kept per id and the latest wins.
func NewTranscript ¶
func NewTranscript(path string) *Transcript
NewTranscript follows the transcript at path.
func (*Transcript) Update ¶
func (t *Transcript) Update() (Tokens, error)
Update reads what was appended since the last call and returns the totals. A partial last line is left for next time.