Documentation
¶
Overview ¶
Package codex reads `codex exec --json` runs.
The stream reports usage once, at turn.completed, as a running total for the thread, and one prompt is one turn. So the budget is watched in the rollout file Codex writes during the turn, which also gives per-request rows. The stream stays as the check on the file and as the record when it cannot be read.
Index ¶
- Constants
- func ReadHomeAnswer(home string, since time.Time) (string, error)
- func ReadStreamAnswer(stream io.Reader) (string, error)
- type Agent
- func (Agent) GatewayArgs(base string) []string
- func (Agent) GatewayBypass(argv []string) (string, error)
- func (Agent) GatewayEnv(_, key string) []string
- func (Agent) Name() string
- func (Agent) NewSession(plan adapter.Plan) adapter.Session
- func (Agent) Plan(argv []string, _ decimal.Decimal) (adapter.Plan, error)
- func (Agent) ReadHome(home string, since time.Time) (adapter.Report, error)
- type Session
Constants ¶
const ( // UnknownModel stands in when neither the command nor the config names // a model. It prices at the catalog's fallback tier. UnknownModel = "unknown" )
Variables ¶
This section is empty.
Functions ¶
func ReadHomeAnswer ¶
ReadHomeAnswer returns the answer a Codex run that already ended left in its Codex home: the last agent message of the latest completed turn, from the rollout files of threads no other thread started. A subagent's answer went to the thread that started it, not to the run. A file last written before since belongs to an earlier job and is not read; a zero since reads every file.
func ReadStreamAnswer ¶
ReadStreamAnswer returns the answer a codex exec --json run ended with, as codex exec keeps its final message: the last agent message completed in a turn that completed. A turn that failed leaves no answer, and nothing else the stream carries is kept.
Types ¶
type Agent ¶
type Agent struct{}
Agent is the Codex CLI.
func (Agent) GatewayArgs ¶
GatewayArgs points Codex's built-in OpenAI provider at the gateway's OpenAI routes, and selects that provider, so a provider set in a configuration file cannot send requests around the gateway. Codex reads its base URL from configuration alone, and a --config value overrides every configuration file.
func (Agent) GatewayBypass ¶
GatewayBypass names the first flag of the command that would send Codex's requests somewhere other than the gateway: a local provider, or a --config value for a key that chooses the provider or its base URL. It reads the command as Codex does, up to a "--" that ends the options.
func (Agent) GatewayEnv ¶
GatewayEnv gives Codex the run's key as its API key. An OpenAI key beside it would let a request skip the gateway, so it is removed.
func (Agent) NewSession ¶
NewSession starts reading a run of the planned command.
func (Agent) Plan ¶
Plan adds --json. Codex has no budget flag, so the wrapper watches the rollout file, and a run that writes none has nothing holding it to the budget.
func (Agent) ReadHome ¶
ReadHome reads a Codex run that already ended from the Codex home it wrote to: every rollout file under sessions/, the run's own threads and their subagents alike, each read as the wrapper reads a rollout file. The home must be one made for the job, as codex-action's codex-home input makes one. A file last written before since belongs to an earlier job and is not read; a file started before since and written after it holds an earlier job's spend, so the reading is refused. A zero since reads every file.
Costroid did not start this run, so no budget held it: the grade is none. The files do not say how the run billed, but openai/codex-action runs Codex only on an API key, its openai-api-key input, so the rows read measured.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session reads one Codex run. Feed and Tail run on separate goroutines, so the lock covers everything below it.
func (*Session) BilledThroughGateway ¶
func (s *Session) BilledThroughGateway()
BilledThroughGateway reads the run as key-billed: Codex starts on the run's key, which the gateway bills per token upstream, whatever costroid's own environment holds.
func (*Session) Feed ¶
Feed reads one stdout line. Its type is read first, then the fields that type carries, so a field this reader never uses, such as message, can take any shape. A line whose shape this reader does not know is skipped and counted. A turn.completed line that cannot be read stops the run's reading at Finish, because it holds the run's figures.
func (*Session) Finish ¶
Finish returns the run's usage and the grade it earned. Per-request rows from the rollout files stand unless the stream's total contradicts them. A run with neither source reported nothing, and whatever it spent is unknown.