mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
8b7f8af343
We are removing feature-gated shared crates from the `codex-rs` workspace. `codex-common` grouped several unrelated utilities behind `[features]`, which made dependency boundaries harder to reason about and worked against the ongoing effort to eliminate feature flags from workspace crates. Splitting these utilities into dedicated crates under `utils/` aligns this area with existing workspace structure and keeps each dependency explicit at the crate boundary. ## What changed - Removed `codex-rs/common` (`codex-common`) from workspace members and workspace dependencies. - Added six new utility crates under `codex-rs/utils/`: - `codex-utils-cli` - `codex-utils-elapsed` - `codex-utils-sandbox-summary` - `codex-utils-approval-presets` - `codex-utils-oss` - `codex-utils-fuzzy-match` - Migrated the corresponding modules out of `codex-common` into these crates (with tests), and added matching `BUILD.bazel` targets. - Updated direct consumers to use the new crates instead of `codex-common`: - `codex-rs/cli` - `codex-rs/tui` - `codex-rs/exec` - `codex-rs/app-server` - `codex-rs/mcp-server` - `codex-rs/chatgpt` - `codex-rs/cloud-tasks` - Updated workspace lockfile entries to reflect the new dependency graph and removal of `codex-common`.
82 lines
2.5 KiB
Rust
82 lines
2.5 KiB
Rust
//! Entry-point for the `codex-exec` binary.
|
|
//!
|
|
//! When this CLI is invoked normally, it parses the standard `codex-exec` CLI
|
|
//! options and launches the non-interactive Codex agent. However, if it is
|
|
//! invoked with arg0 as `codex-linux-sandbox`, we instead treat the invocation
|
|
//! as a request to run the logic for the standalone `codex-linux-sandbox`
|
|
//! executable (i.e., parse any -s args and then run a *sandboxed* command under
|
|
//! Landlock + seccomp.
|
|
//!
|
|
//! This allows us to ship a completely separate set of functionality as part
|
|
//! of the `codex-exec` binary.
|
|
use clap::Parser;
|
|
use codex_arg0::arg0_dispatch_or_else;
|
|
use codex_exec::Cli;
|
|
use codex_exec::run_main;
|
|
use codex_utils_cli::CliConfigOverrides;
|
|
|
|
#[derive(Parser, Debug)]
|
|
struct TopCli {
|
|
#[clap(flatten)]
|
|
config_overrides: CliConfigOverrides,
|
|
|
|
#[clap(flatten)]
|
|
inner: Cli,
|
|
}
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
arg0_dispatch_or_else(|codex_linux_sandbox_exe| async move {
|
|
let top_cli = TopCli::parse();
|
|
// Merge root-level overrides into inner CLI struct so downstream logic remains unchanged.
|
|
let mut inner = top_cli.inner;
|
|
inner
|
|
.config_overrides
|
|
.raw_overrides
|
|
.splice(0..0, top_cli.config_overrides.raw_overrides);
|
|
|
|
run_main(inner, codex_linux_sandbox_exe).await?;
|
|
Ok(())
|
|
})
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn top_cli_parses_resume_prompt_after_config_flag() {
|
|
const PROMPT: &str = "echo resume-with-global-flags-after-subcommand";
|
|
let cli = TopCli::parse_from([
|
|
"codex-exec",
|
|
"resume",
|
|
"--last",
|
|
"--json",
|
|
"--model",
|
|
"gpt-5.2-codex",
|
|
"--config",
|
|
"reasoning_level=xhigh",
|
|
"--dangerously-bypass-approvals-and-sandbox",
|
|
"--skip-git-repo-check",
|
|
PROMPT,
|
|
]);
|
|
|
|
let Some(codex_exec::Command::Resume(args)) = cli.inner.command else {
|
|
panic!("expected resume command");
|
|
};
|
|
let effective_prompt = args.prompt.clone().or_else(|| {
|
|
if args.last {
|
|
args.session_id.clone()
|
|
} else {
|
|
None
|
|
}
|
|
});
|
|
assert_eq!(effective_prompt.as_deref(), Some(PROMPT));
|
|
assert_eq!(cli.config_overrides.raw_overrides.len(), 1);
|
|
assert_eq!(
|
|
cli.config_overrides.raw_overrides[0],
|
|
"reasoning_level=xhigh"
|
|
);
|
|
}
|
|
}
|