Documentation
¶
Overview ¶
Package codex implements an event-level adapter for the Codex CLI. Codex records usage in JSONL session transcripts under CODEX_HOME (default ~/.codex). Each `token_count` event carries either a per-turn delta (info.last_token_usage) or a cumulative running total (info.total_token_usage); we prefer the per-turn delta and otherwise derive deltas with a saturating subtraction against a per-file running previous total.
Token accounting follows OpenAI semantics: cached tokens are a SUBSET of input tokens, so we map Input = input-cached and CacheRead = cached so the components sum to the provider total without double counting.
Index ¶
- Constants
- func New() adapter.Adapter
- type Adapter
- func (Adapter) Capabilities() model.ToolCapability
- func (a Adapter) Collect(ctx context.Context, src adapter.Source) (adapter.Observation, error)
- func (a Adapter) CollectIncremental(ctx context.Context, src adapter.Source, cp *model.SourceCheckpoint) (adapter.Observation, error)
- func (a Adapter) Discover(ctx context.Context, cfg adapter.DiscoverConfig) ([]adapter.Source, error)
- func (Adapter) DisplayName() string
- func (Adapter) ID() string
Constants ¶
const HomeEnv = "CODEX_HOME"
HomeEnv names the environment variable that moves the Codex home, and with it every session transcript this adapter reads. Exported for the same reason claudecode.ConfigDirEnv is: what gets collected is decided here, not by the defaults, and a supervised install must account for that.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adapter ¶
type Adapter struct{}
Adapter reads Codex CLI session transcripts. Read-only.
func (Adapter) Capabilities ¶
func (Adapter) Capabilities() model.ToolCapability
Capabilities declares what this project can say about Codex.
Cost is COMPUTED: nothing here calls SetCost. Activity is RECORDED BUT UNATTRIBUTED, and that is a property of the source rather than an omission: its token_count records share no identity with its function_call / custom_tool_call records (zero of 261,938 local token_count records carry a turn_id, while every call does), so parseCallLine leaves UsageDedupKey empty rather than making a positional guess.
func (Adapter) CollectIncremental ¶
func (a Adapter) CollectIncremental(ctx context.Context, src adapter.Source, cp *model.SourceCheckpoint) (adapter.Observation, error)
CollectIncremental reads only what is new since cp: an unchanged size+mtime skips the file entirely; growth tail-reads from the stored offset with the persisted cumulative baseline; any shrink or same-size rewrite re-reads from zero (re-derived dedup keys collapse in the store). A nil cp is a full read.
func (Adapter) Discover ¶
func (a Adapter) Discover(ctx context.Context, cfg adapter.DiscoverConfig) ([]adapter.Source, error)
Discover locates *.jsonl session files. For each home it scans <home>/sessions (or <home> itself if no sessions dir) plus <home>/archived_sessions if present. The Source.Meta["root"] records the sessions root so Collect can compute the session id as a path relative to it.
func (Adapter) DisplayName ¶
DisplayName returns the human-friendly name.