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.
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.