Compare commits

...

3 Commits

Author SHA1 Message Date
Michael Bolin
1ccd7af0b3 feat: support dotenv (including ~/.codex/.env) 2025-07-22 10:45:00 -07:00
Michael Bolin
dfa9a44202 feat: support dotenv 2025-07-22 10:19:42 -07:00
Michael Bolin
d5809ef6ef chore: install an extension for TOML syntax highlighting in the devcontainer 2025-07-22 10:11:07 -07:00
10 changed files with 35 additions and 3 deletions

View File

@@ -21,7 +21,7 @@
"settings": {
"terminal.integrated.defaultProfile.linux": "bash"
},
"extensions": ["rust-lang.rust-analyzer"]
"extensions": ["rust-lang.rust-analyzer", "tamasfe.even-better-toml"]
}
}
}

8
codex-rs/Cargo.lock generated
View File

@@ -648,6 +648,7 @@ version = "0.0.0"
dependencies = [
"clap",
"codex-core",
"dotenvy",
"serde",
"toml 0.9.1",
]
@@ -794,6 +795,7 @@ version = "0.0.0"
dependencies = [
"anyhow",
"assert_cmd",
"codex-common",
"codex-core",
"codex-linux-sandbox",
"mcp-types",
@@ -1272,6 +1274,12 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "dotenvy"
version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]]
name = "dupe"
version = "0.9.1"

View File

@@ -9,6 +9,7 @@ use codex_cli::SeatbeltCommand;
use codex_cli::login::run_login_with_chatgpt;
use codex_cli::proto;
use codex_common::CliConfigOverrides;
use codex_common::load_dotenv;
use codex_exec::Cli as ExecCli;
use codex_tui::Cli as TuiCli;
use std::path::PathBuf;
@@ -99,6 +100,8 @@ fn main() -> anyhow::Result<()> {
}
async fn cli_main(codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()> {
load_dotenv();
let cli = MultitoolCli::parse();
match cli.subcommand {

View File

@@ -9,11 +9,12 @@ workspace = true
[dependencies]
clap = { version = "4", features = ["derive", "wrap_help"], optional = true }
codex-core = { path = "../core" }
dotenvy = { version = "0.15.7", optional = true }
toml = { version = "0.9", optional = true }
serde = { version = "1", optional = true }
[features]
# Separate feature so that `clap` is not a mandatory dependency.
cli = ["clap", "toml", "serde"]
cli = ["clap", "dotenvy", "toml", "serde"]
elapsed = []
sandbox_summary = []

View File

@@ -0,0 +1,7 @@
/// Load env vars from ~/.codex/.env and `$(pwd)/.env`.
pub fn load_dotenv() {
if let Ok(codex_home) = codex_core::config::find_codex_home() {
dotenvy::from_path(codex_home.join(".env")).ok();
}
dotenvy::dotenv().ok();
}

View File

@@ -1,6 +1,12 @@
#[cfg(feature = "cli")]
mod approval_mode_cli_arg;
#[cfg(feature = "cli")]
mod dotenv;
#[cfg(feature = "cli")]
pub use dotenv::load_dotenv;
#[cfg(feature = "elapsed")]
pub mod elapsed;

View File

@@ -539,7 +539,7 @@ fn default_model() -> String {
/// function will Err if the path does not exist.
/// - If `CODEX_HOME` is not set, this function does not verify that the
/// directory exists.
fn find_codex_home() -> std::io::Result<PathBuf> {
pub fn find_codex_home() -> std::io::Result<PathBuf> {
// Honor the `CODEX_HOME` environment variable when it is set to allow users
// (and tests) to override the default location.
if let Ok(val) = std::env::var("CODEX_HOME") {

View File

@@ -10,6 +10,7 @@ use std::path::PathBuf;
use std::sync::Arc;
pub use cli::Cli;
use codex_common::load_dotenv;
use codex_core::codex_wrapper;
use codex_core::config::Config;
use codex_core::config::ConfigOverrides;
@@ -31,6 +32,8 @@ use tracing_subscriber::EnvFilter;
use crate::event_processor::EventProcessor;
pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()> {
load_dotenv();
let Cli {
images,
model,

View File

@@ -16,6 +16,7 @@ workspace = true
[dependencies]
anyhow = "1"
codex-common = { path = "../common", features = ["cli"] }
codex-core = { path = "../core" }
codex-linux-sandbox = { path = "../linux-sandbox" }
mcp-types = { path = "../mcp-types" }

View File

@@ -4,6 +4,7 @@
use std::io::Result as IoResult;
use std::path::PathBuf;
use codex_common::load_dotenv;
use mcp_types::JSONRPCMessage;
use tokio::io::AsyncBufReadExt;
use tokio::io::AsyncWriteExt;
@@ -38,6 +39,8 @@ pub use crate::patch_approval::PatchApprovalResponse;
const CHANNEL_CAPACITY: usize = 128;
pub async fn run_main(codex_linux_sandbox_exe: Option<PathBuf>) -> IoResult<()> {
load_dotenv();
// Install a simple subscriber so `tracing` output is visible. Users can
// control the log level with `RUST_LOG`.
tracing_subscriber::fmt()