codex

package
v0.174.0-rc.31 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 23 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

Index

Constants

View Source
const (
	EnvAgent = "BEEKEEPER_CODEX_AGENT"
	EnvName  = "BEEKEEPER_AGENT_NAME"
)

Environment variables beekeeper sets on a codex agent's unit, which codex passes down to every tool shell and hook invocation.

View Source
const (
	StateBusy = "busy"
	StateIdle = "idle"
)

Session states written to StatePath(inbox) by the runner and read by Discover.

View Source
const Comm = "codex"

Comm is the Codex CLI executable name.

View Source
const DefaultProjectDocMaxBytes = 262144

DefaultProjectDocMaxBytes is the worker config.toml cap for AGENTS.md docs.

View Source
const Harness = "codex"

Harness is Session.Harness and Start.Harness for a Codex CLI session.

View Source
const HostPrefix = "codex_"

HostPrefix is the prefix of a codex agent's HostSession on the roster: codex_<start id>.

View Source
const StateEnded = "ended"

StateEnded is Session.State when a Codex session is no longer running.

Variables

View Source
var ErrNotRunning = errors.New("codex session is not running")

ErrNotRunning is returned by Send when no codex runner holds the inbox FIFO open for reading.

Functions

func Confirm

func Confirm(inbox string) error

Confirm clears the Inflight message from inbox's persistent queue once codex has accepted the turn on stdin.

func DefaultAuthFile

func DefaultAuthFile(userHome string) string

DefaultAuthFile is the default location of the user's Codex OAuth file.

func DefaultUserConfigFile

func DefaultUserConfigFile(userHome string) string

DefaultUserConfigFile is the default location of the user's Codex config.toml.

func DefaultUserSessionsDir

func DefaultUserSessionsDir(userHome string) string

DefaultUserSessionsDir is the default location of the user's Codex sessions directory.

func Discover

func Discover(stateDir, sessionsDir string, t *proc.Table, now time.Time) []*claude.Session

Discover finds running Codex sessions from the process table and matches them to their rollout transcripts. It inspects both beekeeper's own `codex-run` unit runners and standalone `codex` CLI processes (ignoring `codex app-server`), and only sets HostID (`codex_<id>`) when the process carries BEEKEEPER_CODEX_AGENT in its environment.

func Drain

func Drain(inbox string) ([]string, error)

Drain atomically pops the next message from inbox's persistent queue and marks it Inflight until Confirm is called. If a previous Inflight message was never confirmed (for example, codex exited before accepting it), Drain returns that Inflight message first so it is not lost.

func Ended

func Ended(stateDir, sessionsDir string, running []*claude.Session, since time.Time) []*claude.Session

Ended returns the Codex sessions written to since `since` that no running session runs, most recently active first.

func EnsureHome

func EnsureHome(codexHome, authFile, userConfigFile, exe, prelude string) error

EnsureHome prepares an isolated CODEX_HOME directory for a beekeeper codex worker: symlinks authFile to auth.json when present, generates config.toml keeping only [projects.*] from userConfigFile, writes hooks.json, and writes zsh/.zshenv and zsh/.zprofile for non-interactive tool shells.

func ExecArgv

func ExecArgv(bin, model string) []string

ExecArgv is the command line for a codex session's first turn, reading the prompt from stdin.

func Follow

func Follow(path string, n int) ([]claude.Turn, error)

Follow is Tail with the agent's tool calls among the turns, as claude.Follow returns them.

func HasRollouts

func HasRollouts(stateDir, sessionsDir string, extraDirs ...string) bool

HasRollouts reports whether at least one rollout `.jsonl` file exists under the isolated worker CODEX_HOME sessions directory or sessionsDir.

func HomeDir

func HomeDir(stateDir string) string

HomeDir is the isolated CODEX_HOME directory for beekeeper-started codex workers.

func HomeSessionsDir

func HomeSessionsDir(stateDir string) string

HomeSessionsDir is the sessions directory inside the isolated CODEX_HOME.

func HooksJSON

func HooksJSON(exe string) ([]byte, error)

HooksJSON returns the hooks.json content for the isolated CODEX_HOME.

func InboxPath

func InboxPath(stateDir, id string) string

InboxPath is the FIFO inbox path for a beekeeper-started codex agent id.

func LockPath

func LockPath(inbox string) string

LockPath is the flock file protecting QueuePath(inbox).

func LogPath

func LogPath(stateDir, id string) string

LogPath is the JSONL stream log path for a beekeeper-started codex agent id.

func MakeInbox

func MakeInbox(inbox string) error

MakeInbox creates the named pipe at inbox (mode 0600) and its lock file.

func MergeConfigTOML

func MergeConfigTOML(existing []byte) ([]byte, error)

MergeConfigTOML parses existing user config.toml bytes structurally, retains only the [projects.*] trust tables, and returns a clean worker config.toml with deterministic worker settings and feature flags.

func QueuePath

func QueuePath(inbox string) string

QueuePath is the persistent JSON queue backing inbox.

func ReadState

func ReadState(inbox string) string

ReadState reads the session state ("busy" or "idle") for inbox.

func ReadThread

func ReadThread(stateDir, inbox string) string

ReadThread returns the recorded Codex thread_id for inbox, or "".

func ReadTranscript

func ReadTranscript(path string, now time.Time, sessionModel ...string) (claude.Work, claude.Activity)

ReadTranscript reads a Codex rollout file into the Work and Activity records that board, metrics, sessions and capacity use.

func RecordThread

func RecordThread(stateDir, inbox, threadID string) error

RecordThread records the Codex thread_id for the session owning inbox.

func RemoveInbox

func RemoveInbox(inbox string) (removed bool, err error)

RemoveInbox removes the inbox FIFO at inbox, its queue, lock and state files, its stream log (<id>.jsonl), its thread file (<id>.thread) and its thread link (threads/<threadID>); removed is false when none of them existed.

func ResolveInbox

func ResolveInbox(stateDir, threadID string) string

ResolveInbox finds the FIFO inbox path for a codex session from its BEEKEEPER_CODEX_AGENT environment variable or its thread_id link file.

func ResumeArgv

func ResumeArgv(bin, model, threadID string) []string

ResumeArgv is the command line for a codex session's subsequent turns, resuming threadID and reading the prompt from stdin.

func Run

func Run(ctx context.Context, inbox, logPath, bin, model string, stderr io.Writer) error

Run drives a Codex CLI session one turn at a time from its persistent FIFO inbox. The first message runs `codex exec --json ... -`, captures the emitted thread_id, and subsequent messages run `codex exec resume --json ... <thread_id> -`. Messages arriving while a turn is running stay in the persistent queue and run as the next turn as soon as the active turn finishes.

func Send

func Send(inbox, text string) error

Send appends text to the persistent queue of inbox and signals the FIFO so an idle codex-run wakes at once. If no process holds the FIFO open for reading, Send returns ErrNotRunning without modifying the queue.

func SpendTranscripts

func SpendTranscripts(stateDir, sessionsDir string, from, to time.Time) []claude.SpendTranscript

SpendTranscripts reads the Codex rollout files under stateDir's isolated CODEX_HOME and sessionsDir modified since `from`, returning the token usage requests within [from, to] for `beekeeper spend`.

func StatePath

func StatePath(inbox string) string

StatePath is the state file ("busy" or "idle") for inbox.

func Tail

func Tail(path string, n int) ([]claude.Turn, error)

Tail returns the last n turns of a Codex rollout file: user prompts and assistant replies, without developer instructions, tool calls or tool results.

func ThreadLinkPath

func ThreadLinkPath(stateDir, threadID string) string

ThreadLinkPath maps a Codex thread_id back to the agent's inbox path.

func ThreadPath

func ThreadPath(stateDir, id string) string

ThreadPath is the file recording the Codex thread_id of a beekeeper-started codex agent id.

func WriteState

func WriteState(inbox, st string)

WriteState writes the session state ("busy" or "idle") for inbox.

func ZshDir

func ZshDir(codexHome string) string

ZshDir is the ZDOTDIR inside the isolated CODEX_HOME.

Types

type QueuedMessage

type QueuedMessage struct {
	ID   string `json:"id"`
	Text string `json:"text"`
}

QueuedMessage is one wake message tracked in the persistent inbox queue with a unique ID so retries and restarts deduplicate already-delivered messages.

type UsageCredits

type UsageCredits struct {
	HasCredits bool
	Unlimited  bool
	Balance    *float64
}

UsageCredits holds the optional credit balance section of a Codex `rate_limits` payload.

type UsageReading

type UsageReading struct {
	At       time.Time
	FiveHour *UsageWindow
	SevenDay *UsageWindow
	PlanType string
	Credits  *UsageCredits
}

UsageReading is the freshest account-level plan usage event read across Codex rollout transcripts.

func ParseRateLimits

func ParseRateLimits(raw json.RawMessage, at time.Time) (UsageReading, error)

ParseRateLimits parses a Codex `rate_limits` JSON object (or an envelope containing `rate_limits`) at event timestamp `at`.

func ReadUsage

func ReadUsage(stateDir, sessionsDir string, extraDirs ...string) (UsageReading, error)

ReadUsage scans Codex rollout transcripts across the isolated worker CODEX_HOME (`<stateDir>/codex/home/sessions`) and `sessionsDir` (`~/.codex/sessions`), selects the freshest `token_count` event across all sessions (since all sessions share one account), and parses its `rate_limits` payload.

A rollout transcript that has not yet written any `token_count` event (such as a newly started session that has written only `session_meta` or `turn_context`) produces no candidate and never shadows a valid reading from another session. An explicit invalid, stopped or truncated/corrupt rollout event is recorded at its timestamp (or the later of the previous line's timestamp and the file's mtime) and fails closed when it is the freshest event.

type UsageWindow

type UsageWindow struct {
	UsedPercent   float64
	ResetsAt      time.Time
	WindowMinutes int
}

UsageWindow is one subscription rate-limit window reported by Codex CLI in a rollout `token_count` event (`primary` or `secondary`).

Jump to

Keyboard shortcuts

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