pub struct Codex { /* private fields */ }Expand description
Shared Codex CLI client configuration.
Holds the binary path, working directory, environment variables, global
arguments, timeout, and retry policy. Cheap to Clone; intended to be
created once and reused across many command invocations.
§Example
let codex = codex_wrapper::Codex::builder()
.env("OPENAI_API_KEY", "sk-...")
.timeout_secs(120)
.build()?;Implementations§
Source§impl Codex
impl Codex
Sourcepub fn builder() -> CodexBuilder
pub fn builder() -> CodexBuilder
Create a new CodexBuilder.
Sourcepub fn working_dir(&self) -> Option<&Path>
pub fn working_dir(&self) -> Option<&Path>
Working directory for command execution, if set.
Sourcepub fn with_working_dir(&self, dir: impl Into<PathBuf>) -> Self
pub fn with_working_dir(&self, dir: impl Into<PathBuf>) -> Self
Return a clone of this client with a different working directory.
Sourcepub fn config(&self) -> Result<Option<CodexConfig>>
pub fn config(&self) -> Result<Option<CodexConfig>>
Read config.toml for this client’s CODEX_HOME.
Uses the same effective environment as spawned commands. A client
built with clear_env does not fall back to
ambient CODEX_HOME or HOME values.
Ok(None) when there is no config file. Requires the config feature.
See crate::config for what is typed and what stays raw.
Sourcepub fn auth_status(&self) -> AuthStatus
pub fn auth_status(&self) -> AuthStatus
Which credential this client’s CLI would use, without spawning it.
Honors a CODEX_HOME set on this client via
env, falling back to the process environment
unless clear_env was selected.
See crate::auth for what the strategies mean and how they were
determined.
use codex_wrapper::Codex;
let codex = Codex::builder().build()?;
if !codex.auth_status().is_configured() {
eprintln!("no credentials; run `codex login`");
}pub async fn cli_version(&self) -> Result<CliVersion>
Sourcepub async fn check_version(&self, minimum: &CliVersion) -> Result<CliVersion>
pub async fn check_version(&self, minimum: &CliVersion) -> Result<CliVersion>
Verify the installed CLI meets a minimum version requirement.
Returns Error::VersionMismatch if the installed version is too old.
Sourcepub fn tested_cli_version_range(&self) -> (CliVersion, CliVersion)
pub fn tested_cli_version_range(&self) -> (CliVersion, CliVersion)
The tested-against CLI version range this client reports on.
Defaults to TESTED_CLI_VERSION_MIN and TESTED_CLI_VERSION_MAX;
override with CodexBuilder::tested_cli_version_range.
Sourcepub async fn cli_version_status(&self) -> Result<CliVersionStatus>
pub async fn cli_version_status(&self) -> Result<CliVersionStatus>
Classify the installed CLI against the tested-against range.
Emits a tracing::warn! when outside the range, and returns the typed
status either way. This reports; it does not fail. Most CLI releases
break nothing, so refusing to run against an unrecognized version is
worse than saying so. Use
ensure_tested_cli_version when you
do want a hard gate.
Intended for one-shot use at startup rather than before every command:
it spawns codex --version.
Sourcepub async fn ensure_tested_cli_version(&self) -> Result<CliVersion>
pub async fn ensure_tested_cli_version(&self) -> Result<CliVersion>
Like cli_version_status, but returns
Error::UntestedCliVersion when the installed CLI is outside the
tested range.
This is the opt-in hard gate. It is a method rather than a
CodexBuilder option because CodexBuilder::build is synchronous
and never spawns the binary; enforcing a version there would mean
running a subprocess inside a constructor.