codex

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const CodexModelDiscoveryFreshnessWindow = 24 * time.Hour
View Source
const DefaultCodexQuotaStaleAfter = 15 * time.Minute

Variables

This section is empty.

Functions

func CodexAuthPath

func CodexAuthPath() (string, error)

CodexAuthPath returns the local Codex auth file used for account metadata.

func CodexQuotaCachePath

func CodexQuotaCachePath() (string, error)

CodexQuotaCachePath returns the durable location for the Codex quota cache.

func CodexQuotaSnapshotAge

func CodexQuotaSnapshotAge(snapshot *CodexQuotaSnapshot, now time.Time) time.Duration

CodexQuotaSnapshotAge reports snapshot age relative to now.

func CodexSessionsRoot

func CodexSessionsRoot() (string, error)

CodexSessionsRoot returns the Codex session JSONL root. Tests may override this with FIZEAU_CODEX_SESSIONS_DIR; normal operation follows CODEX_HOME.

func DefaultCodexModelDiscovery

func DefaultCodexModelDiscovery() harnesses.ModelDiscoverySnapshot

func IsCodexQuotaFresh

func IsCodexQuotaFresh(snapshot *CodexQuotaSnapshot, now time.Time, staleAfter time.Duration) bool

IsCodexQuotaFresh reports whether a snapshot is present and fresh.

func ReadCodexAccount

func ReadCodexAccount() (*harnesses.AccountInfo, bool)

ReadCodexAccount extracts non-secret account metadata from Codex auth state.

func ReadCodexAccountFrom

func ReadCodexAccountFrom(path string) (*harnesses.AccountInfo, bool)

ReadCodexAccountFrom reads auth.json and extracts email, plan, and org info.

func ReadCodexModelDiscoveryFromCassette

func ReadCodexModelDiscoveryFromCassette(dir string) (harnesses.ModelDiscoverySnapshot, error)

func ReadCodexModelDiscoveryViaPTY

func ReadCodexModelDiscoveryViaPTY(timeout time.Duration, opts ...QuotaPTYOption) (harnesses.ModelDiscoverySnapshot, error)

func ReadCodexQuotaFromCassette

func ReadCodexQuotaFromCassette(dir string) ([]harnesses.QuotaWindow, error)

func ReadCodexQuotaViaPTY

func ReadCodexQuotaViaPTY(timeout time.Duration, opts ...QuotaPTYOption) ([]harnesses.QuotaWindow, error)

func ReadCodexQuotaViaTmux deprecated

func ReadCodexQuotaViaTmux(timeout time.Duration) ([]harnesses.QuotaWindow, error)

ReadCodexQuotaViaTmux starts codex in a detached tmux session, sends /status, captures the output, and returns parsed quota windows.

Deprecated: this is a diagnostic-only legacy path. Supported quota probes use ReadCodexQuotaViaPTY so accepted evidence passes through direct PTY cassettes.

func ResolveCodexModelAlias

func ResolveCodexModelAlias(model string, snapshot harnesses.ModelDiscoverySnapshot) string

func WriteCodexQuota

func WriteCodexQuota(path string, snapshot CodexQuotaSnapshot) error

WriteCodexQuota atomically persists a CodexQuotaSnapshot to path.

Types

type CodexQuotaRoutingDecision

type CodexQuotaRoutingDecision struct {
	PreferCodex     bool
	SnapshotPresent bool
	Fresh           bool
	Age             time.Duration
	Snapshot        *CodexQuotaSnapshot
	Reason          string
}

CodexQuotaRoutingDecision summarises whether foreground routing may select Codex without probing the CLI inline.

func DecideCodexQuotaRouting

func DecideCodexQuotaRouting(snapshot *CodexQuotaSnapshot, now time.Time, staleAfter time.Duration) CodexQuotaRoutingDecision

DecideCodexQuotaRouting turns a durable quota snapshot into a foreground routing decision. Missing, stale, empty, or blocked quota evidence keeps Codex out of automatic routing; explicit Harness=codex remains available.

func ReadCodexQuotaRoutingDecision

func ReadCodexQuotaRoutingDecision(now time.Time, staleAfter time.Duration) CodexQuotaRoutingDecision

ReadCodexQuotaRoutingDecision reads the default cache and produces a routing decision in one call.

type CodexQuotaSnapshot

type CodexQuotaSnapshot struct {
	CapturedAt time.Time               `json:"captured_at"`
	Windows    []harnesses.QuotaWindow `json:"windows"`
	Source     string                  `json:"source"`
	Account    *harnesses.AccountInfo  `json:"account,omitempty"`
}

CodexQuotaSnapshot captures Codex subscription quota windows in a durable cache so foreground service status calls do not need to spawn a live PTY probe.

func CodexQuotaSnapshotFromTokenCountRateLimits

func CodexQuotaSnapshotFromTokenCountRateLimits(timestamp string, fallbackCapturedAt time.Time, rateLimits json.RawMessage) (*CodexQuotaSnapshot, bool)

CodexQuotaSnapshotFromTokenCountRateLimits builds a quota snapshot from a token_count.rate_limits payload. fallbackCapturedAt must be evidence time: session readers pass file mtime, while live DDx-owned streams may pass now.

func ReadCodexQuota

func ReadCodexQuota() (*CodexQuotaSnapshot, bool)

ReadCodexQuota reads the default Codex quota cache.

func ReadCodexQuotaFrom

func ReadCodexQuotaFrom(path string) (*CodexQuotaSnapshot, bool)

ReadCodexQuotaFrom reads one Codex quota snapshot.

func ReadCodexQuotaFromSessionTokenCounts

func ReadCodexQuotaFromSessionTokenCounts(opts ...CodexSessionTokenCountOption) (*CodexQuotaSnapshot, bool)

ReadCodexQuotaFromSessionTokenCounts returns the newest fresh quota snapshot found in Codex token_count events. It never reads session content for historical analytics and returns false for missing, stale, or malformed evidence so callers can fall back to the live PTY probe.

func RefreshCodexQuotaViaPTY

func RefreshCodexQuotaViaPTY(timeout time.Duration, opts ...QuotaPTYOption) (CodexQuotaSnapshot, error)

type CodexSessionTokenCountOption

type CodexSessionTokenCountOption func(*codexSessionTokenCountConfig)

CodexSessionTokenCountOption adjusts bounded session token_count scanning.

func WithCodexSessionTokenCountLimits

func WithCodexSessionTokenCountLimits(maxFiles int, maxBytesPerFile int64, maxLineBytes int) CodexSessionTokenCountOption

func WithCodexSessionTokenCountNow

func WithCodexSessionTokenCountNow(now time.Time) CodexSessionTokenCountOption

func WithCodexSessionTokenCountRoot

func WithCodexSessionTokenCountRoot(root string) CodexSessionTokenCountOption

type QuotaPTYOption

type QuotaPTYOption func(*quotaPTYOptions)

func WithQuotaPTYCassetteDir

func WithQuotaPTYCassetteDir(dir string) QuotaPTYOption

func WithQuotaPTYCommand

func WithQuotaPTYCommand(binary string, args ...string) QuotaPTYOption

func WithQuotaPTYEnv

func WithQuotaPTYEnv(env ...string) QuotaPTYOption

func WithQuotaPTYWorkdir

func WithQuotaPTYWorkdir(workdir string) QuotaPTYOption

type Runner

type Runner struct {
	// Binary is the absolute path to the codex executable. When empty the
	// runner resolves "codex" via PATH at Execute time.
	Binary string

	// BaseArgs is prepended to the per-request argument list.
	// Codex default: ["exec", "--json"]
	BaseArgs []string

	// PromptMode controls how the prompt is delivered:
	//   "arg" (default) — prompt is appended as the final positional argument
	//   "stdin"         — prompt is piped on stdin
	PromptMode string

	// EventBuffer overrides the per-Execute channel buffer size.
	EventBuffer int
}

Runner is the subprocess-backed codex harness. It launches codex in exec --json mode, parses each JSONL line into harness Events, and emits a final Event when the subprocess exits.

func (*Runner) Execute

func (r *Runner) Execute(ctx context.Context, req harnesses.ExecuteRequest) (<-chan harnesses.Event, error)

Execute runs one resolved request through the codex CLI and emits JSONL-derived events on the returned channel.

func (*Runner) HealthCheck

func (r *Runner) HealthCheck(ctx context.Context) error

HealthCheck verifies the codex binary is present.

func (*Runner) Info

func (r *Runner) Info() harnesses.HarnessInfo

Info returns identity + capability metadata for this harness.

Jump to

Keyboard shortcuts

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