mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
4bf81373a7
I accidentally missed this in https://github.com/openai/codex/pull/1086.
107 lines
2.7 KiB
Rust
107 lines
2.7 KiB
Rust
use clap::Parser;
|
||
use codex_cli::LandlockCommand;
|
||
use codex_cli::SeatbeltCommand;
|
||
use codex_cli::proto;
|
||
use codex_exec::Cli as ExecCli;
|
||
use codex_tui::Cli as TuiCli;
|
||
use std::path::PathBuf;
|
||
|
||
use crate::proto::ProtoCli;
|
||
|
||
/// Codex CLI
|
||
///
|
||
/// If no subcommand is specified, options will be forwarded to the interactive CLI.
|
||
#[derive(Debug, Parser)]
|
||
#[clap(
|
||
author,
|
||
version,
|
||
// If a sub‑command is given, ignore requirements of the default args.
|
||
subcommand_negates_reqs = true
|
||
)]
|
||
struct MultitoolCli {
|
||
#[clap(flatten)]
|
||
interactive: TuiCli,
|
||
|
||
#[clap(subcommand)]
|
||
subcommand: Option<Subcommand>,
|
||
}
|
||
|
||
#[derive(Debug, clap::Subcommand)]
|
||
enum Subcommand {
|
||
/// Run Codex non-interactively.
|
||
#[clap(visible_alias = "e")]
|
||
Exec(ExecCli),
|
||
|
||
/// Experimental: run Codex as an MCP server.
|
||
Mcp,
|
||
|
||
/// Run the Protocol stream via stdin/stdout
|
||
#[clap(visible_alias = "p")]
|
||
Proto(ProtoCli),
|
||
|
||
/// Internal debugging commands.
|
||
Debug(DebugArgs),
|
||
}
|
||
|
||
#[derive(Debug, Parser)]
|
||
struct DebugArgs {
|
||
#[command(subcommand)]
|
||
cmd: DebugCommand,
|
||
}
|
||
|
||
#[derive(Debug, clap::Subcommand)]
|
||
enum DebugCommand {
|
||
/// Run a command under Seatbelt (macOS only).
|
||
Seatbelt(SeatbeltCommand),
|
||
|
||
/// Run a command under Landlock+seccomp (Linux only).
|
||
Landlock(LandlockCommand),
|
||
}
|
||
|
||
#[derive(Debug, Parser)]
|
||
struct ReplProto {}
|
||
|
||
fn main() -> anyhow::Result<()> {
|
||
codex_linux_sandbox::run_with_sandbox(|codex_linux_sandbox_exe| async move {
|
||
cli_main(codex_linux_sandbox_exe).await?;
|
||
Ok(())
|
||
})
|
||
}
|
||
|
||
async fn cli_main(codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()> {
|
||
let cli = MultitoolCli::parse();
|
||
|
||
match cli.subcommand {
|
||
None => {
|
||
codex_tui::run_main(cli.interactive, codex_linux_sandbox_exe)?;
|
||
}
|
||
Some(Subcommand::Exec(exec_cli)) => {
|
||
codex_exec::run_main(exec_cli, codex_linux_sandbox_exe).await?;
|
||
}
|
||
Some(Subcommand::Mcp) => {
|
||
codex_mcp_server::run_main(codex_linux_sandbox_exe).await?;
|
||
}
|
||
Some(Subcommand::Proto(proto_cli)) => {
|
||
proto::run_main(proto_cli).await?;
|
||
}
|
||
Some(Subcommand::Debug(debug_args)) => match debug_args.cmd {
|
||
DebugCommand::Seatbelt(seatbelt_command) => {
|
||
codex_cli::debug_sandbox::run_command_under_seatbelt(
|
||
seatbelt_command,
|
||
codex_linux_sandbox_exe,
|
||
)
|
||
.await?;
|
||
}
|
||
DebugCommand::Landlock(landlock_command) => {
|
||
codex_cli::debug_sandbox::run_command_under_landlock(
|
||
landlock_command,
|
||
codex_linux_sandbox_exe,
|
||
)
|
||
.await?;
|
||
}
|
||
},
|
||
}
|
||
|
||
Ok(())
|
||
}
|