codex

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package codex runs the Codex CLI in non-interactive mode and parses its JSONL event stream.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildArgs

func BuildArgs(spec RunSpec) []string

BuildArgs adapts a RunSpec to `codex exec` arguments. New sessions and resumptions accept different flag sets, so they are constructed separately.

func Locate

func Locate(explicit string) (string, error)

Locate finds the Codex CLI without guessing at app-bundled alpha binaries.

Types

type ExecRunner

type ExecRunner struct {
	Bin string
}

ExecRunner runs the real Codex CLI.

func (*ExecRunner) Run

func (r *ExecRunner) Run(ctx context.Context, spec RunSpec, hooks Hooks) (RunResult, error)

Run executes Codex with the prompt on stdin, copying JSONL events and stderr to the job directory while keeping only metadata in memory.

type Hooks

type Hooks struct {
	OnStart func(*proc.Process)
}

Hooks lets the job manager terminate the process group on demand.

type ParseResult

type ParseResult struct {
	ThreadID    string
	Usage       *Usage
	Failure     string
	LastMessage string
	Events      int
	BadLines    int
}

ParseResult is the metadata extracted from a JSONL event stream.

func ParseEvents

func ParseEvents(r io.Reader, dump io.Writer) ParseResult

ParseEvents copies every raw line to dump (when non-nil) and extracts the handful of fields the job manager needs. Malformed lines are counted, not fatal: Codex may emit warnings on stdout.

type RunResult

type RunResult struct {
	ExitCode    int
	ThreadID    string
	Usage       *Usage
	Failure     string
	Events      int
	BadLines    int
	LastMessage string
}

RunResult describes a finished (or failed to start) Codex process.

type RunSpec

type RunSpec struct {
	Prompt           string
	Cwd              string
	Sandbox          string
	Network          bool
	Model            string
	Profile          string
	ThreadID         string
	Ephemeral        bool
	IgnoreUserConfig bool
	SkipGitRepoCheck bool
	AddDirs          []string
	Images           []string
	OutputSchemaPath string
	FinalPath        string
	EventsPath       string
	StderrPath       string
}

RunSpec is one `codex exec` invocation.

type Runner

type Runner interface {
	Run(ctx context.Context, spec RunSpec, hooks Hooks) (RunResult, error)
}

Runner abstracts the Codex subprocess for tests.

type Usage

type Usage struct {
	InputTokens           int64 `json:"input_tokens"`
	CachedInputTokens     int64 `json:"cached_input_tokens"`
	OutputTokens          int64 `json:"output_tokens"`
	ReasoningOutputTokens int64 `json:"reasoning_output_tokens"`
}

Usage is the token usage reported by Codex at the end of a turn.

Jump to

Keyboard shortcuts

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