codex

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 17 Imported by: 0

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

View Source
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

func New

func New() adapter.Adapter

New returns a Codex adapter.

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) Collect

func (a Adapter) Collect(ctx context.Context, src adapter.Source) (adapter.Observation, error)

Collect reads one JSONL session file in full and returns its usage events.

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

func (Adapter) DisplayName() string

DisplayName returns the human-friendly name.

func (Adapter) ID

func (Adapter) ID() string

ID returns the stable tool identifier.

Jump to

Keyboard shortcuts

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