codex

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package codex provides the Agent implementation for OpenAI's `codex` CLI. Registration happens in init() — any binary that links this package will have "codex" available in the agent registry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCommand

func BuildCommand(agentSessionID, mode string, resume bool, envExports string) string

BuildCommand builds the codex CLI command string.

agentSessionID is the codex thread UUID (Session.AgentSessionID). On resume:

  • if non-empty: `codex resume <id>` (positional)
  • if empty: `codex resume --last`

In both resume branches the command falls back to a fresh `codex` on non-zero exit — better to land in a usable state than strand the user when the prior session can't be resumed. Crashes, auth failures, or Ctrl-C will also trigger the fallback; that's intentional.

envExports, when non-empty, is prepended verbatim as a shell prelude. It comes from <agent>-env.json via the caller — for codex this lets the user set provider keys or PATH bits that need to be visible to codex's early startup, too early for codex's own config.toml shell policy to take effect.

func DiscoverSessionID

func DiscoverSessionID(spawnStart time.Time) (string, bool)

DiscoverSessionID polls ~/.codex/sessions/ for a rollout file whose mtime is at or after spawnStart and returns its UUID. Empty + false on timeout, missing sessions dir, or any I/O error along the way — callers fall back to `codex resume --last` semantics, which is strictly less precise but still correct.

Implementation: scan the day-directory matching spawnStart's UTC date (plus the previous day if spawnStart is within the first 5 minutes of UTC midnight, to absorb clock skew). The file whose mtime is closest to spawnStart and >= spawnStart wins.

func FindCodexChild

func FindCodexChild(panePID string) string

FindCodexChild finds a codex process among children of the given PID by walking /proc/*/status. Pure Go — no pgrep dependency.

func IsCodexAlive

func IsCodexAlive(pid string) (bool, error)

IsCodexAlive checks if a PID exists and is not a zombie.

func New

func New() agent.Agent

New returns the codex Agent. Exposed (not just via init) so test code that needs a fresh registry can re-register after agent.Reset().

Types

This section is empty.

Jump to

Keyboard shortcuts

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