Documentation
¶
Index ¶
- Constants
- Variables
- func Confirm(inbox string) error
- func DefaultAuthFile(userHome string) string
- func DefaultUserConfigFile(userHome string) string
- func DefaultUserSessionsDir(userHome string) string
- func Discover(stateDir, sessionsDir string, t *proc.Table, now time.Time) []*claude.Session
- func Drain(inbox string) ([]string, error)
- func Ended(stateDir, sessionsDir string, running []*claude.Session, since time.Time) []*claude.Session
- func EnsureHome(codexHome, authFile, userConfigFile, exe, prelude string) error
- func ExecArgv(bin, model string) []string
- func Follow(path string, n int) ([]claude.Turn, error)
- func HasRollouts(stateDir, sessionsDir string, extraDirs ...string) bool
- func HomeDir(stateDir string) string
- func HomeSessionsDir(stateDir string) string
- func HooksJSON(exe string) ([]byte, error)
- func InboxPath(stateDir, id string) string
- func LockPath(inbox string) string
- func LogPath(stateDir, id string) string
- func MakeInbox(inbox string) error
- func MergeConfigTOML(existing []byte) ([]byte, error)
- func QueuePath(inbox string) string
- func ReadState(inbox string) string
- func ReadThread(stateDir, inbox string) string
- func ReadTranscript(path string, now time.Time, sessionModel ...string) (claude.Work, claude.Activity)
- func RecordThread(stateDir, inbox, threadID string) error
- func RemoveInbox(inbox string) (removed bool, err error)
- func ResolveInbox(stateDir, threadID string) string
- func ResumeArgv(bin, model, threadID string) []string
- func Run(ctx context.Context, inbox, logPath, bin, model string, stderr io.Writer) error
- func Send(inbox, text string) error
- func SpendTranscripts(stateDir, sessionsDir string, from, to time.Time) []claude.SpendTranscript
- func StatePath(inbox string) string
- func Tail(path string, n int) ([]claude.Turn, error)
- func ThreadLinkPath(stateDir, threadID string) string
- func ThreadPath(stateDir, id string) string
- func WriteState(inbox, st string)
- func ZshDir(codexHome string) string
- type QueuedMessage
- type UsageCredits
- type UsageReading
- type UsageWindow
Constants ¶
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.
const ( StateBusy = "busy" StateIdle = "idle" )
Session states written to StatePath(inbox) by the runner and read by Discover.
const Comm = "codex"
Comm is the Codex CLI executable name.
const DefaultProjectDocMaxBytes = 262144
DefaultProjectDocMaxBytes is the worker config.toml cap for AGENTS.md docs.
const Harness = "codex"
Harness is Session.Harness and Start.Harness for a Codex CLI session.
const HostPrefix = "codex_"
HostPrefix is the prefix of a codex agent's HostSession on the roster: codex_<start id>.
const StateEnded = "ended"
StateEnded is Session.State when a Codex session is no longer running.
Variables ¶
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 ¶
Confirm clears the Inflight message from inbox's persistent queue once codex has accepted the turn on stdin.
func DefaultAuthFile ¶
DefaultAuthFile is the default location of the user's Codex OAuth file.
func DefaultUserConfigFile ¶
DefaultUserConfigFile is the default location of the user's Codex config.toml.
func DefaultUserSessionsDir ¶
DefaultUserSessionsDir is the default location of the user's Codex sessions directory.
func Discover ¶
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 ¶
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 ¶
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 ¶
ExecArgv is the command line for a codex session's first turn, reading the prompt from stdin.
func Follow ¶
Follow is Tail with the agent's tool calls among the turns, as claude.Follow returns them.
func HasRollouts ¶
HasRollouts reports whether at least one rollout `.jsonl` file exists under the isolated worker CODEX_HOME sessions directory or sessionsDir.
func HomeSessionsDir ¶
HomeSessionsDir is the sessions directory inside the isolated CODEX_HOME.
func MergeConfigTOML ¶
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 ReadThread ¶
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 ¶
RecordThread records the Codex thread_id for the session owning inbox.
func RemoveInbox ¶
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 ¶
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 ¶
ResumeArgv is the command line for a codex session's subsequent turns, resuming threadID and reading the prompt from stdin.
func Run ¶
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 ¶
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 Tail ¶
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 ¶
ThreadLinkPath maps a Codex thread_id back to the agent's inbox path.
func ThreadPath ¶
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.
Types ¶
type QueuedMessage ¶
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 ¶
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.