From 9c259737d31c8ab5d796fbe5f1ba728837d9f14c Mon Sep 17 00:00:00 2001 From: pakrym-oai Date: Tue, 30 Sep 2025 15:33:28 -0700 Subject: [PATCH] Delete codex proto (#4520) --- codex-rs/Cargo.lock | 2 - codex-rs/cli/Cargo.toml | 2 - codex-rs/cli/src/lib.rs | 1 - codex-rs/cli/src/main.rs | 13 ---- codex-rs/cli/src/proto.rs | 133 -------------------------------------- 5 files changed, 151 deletions(-) delete mode 100644 codex-rs/cli/src/proto.rs diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lock index 3e0c28fa..be2982de 100644 --- a/codex-rs/Cargo.lock +++ b/codex-rs/Cargo.lock @@ -771,8 +771,6 @@ dependencies = [ "supports-color", "tempfile", "tokio", - "tracing", - "tracing-subscriber", ] [[package]] diff --git a/codex-rs/cli/Cargo.toml b/codex-rs/cli/Cargo.toml index c62a267c..77f428bb 100644 --- a/codex-rs/cli/Cargo.toml +++ b/codex-rs/cli/Cargo.toml @@ -43,8 +43,6 @@ tokio = { workspace = true, features = [ "rt-multi-thread", "signal", ] } -tracing = { workspace = true } -tracing-subscriber = { workspace = true } [dev-dependencies] assert_cmd = { workspace = true } diff --git a/codex-rs/cli/src/lib.rs b/codex-rs/cli/src/lib.rs index c6d80c0a..c05d570e 100644 --- a/codex-rs/cli/src/lib.rs +++ b/codex-rs/cli/src/lib.rs @@ -1,7 +1,6 @@ pub mod debug_sandbox; mod exit_status; pub mod login; -pub mod proto; use clap::Parser; use codex_common::CliConfigOverrides; diff --git a/codex-rs/cli/src/main.rs b/codex-rs/cli/src/main.rs index 6c65339c..7559e16e 100644 --- a/codex-rs/cli/src/main.rs +++ b/codex-rs/cli/src/main.rs @@ -12,7 +12,6 @@ use codex_cli::login::run_login_with_api_key; use codex_cli::login::run_login_with_chatgpt; use codex_cli::login::run_login_with_device_code; use codex_cli::login::run_logout; -use codex_cli::proto; use codex_cloud_tasks::Cli as CloudTasksCli; use codex_common::CliConfigOverrides; use codex_exec::Cli as ExecCli; @@ -26,7 +25,6 @@ use supports_color::Stream; mod mcp_cmd; use crate::mcp_cmd::McpCli; -use crate::proto::ProtoCli; /// Codex CLI /// @@ -74,10 +72,6 @@ enum Subcommand { /// [experimental] Run the app server. AppServer, - /// Run the Protocol stream via stdin/stdout - #[clap(visible_alias = "p")] - Proto(ProtoCli), - /// Generate shell completion scripts. Completion(CompletionCommand), @@ -319,13 +313,6 @@ async fn cli_main(codex_linux_sandbox_exe: Option) -> anyhow::Result<() ); run_logout(logout_cli.config_overrides).await; } - Some(Subcommand::Proto(mut proto_cli)) => { - prepend_config_flags( - &mut proto_cli.config_overrides, - root_config_overrides.clone(), - ); - proto::run_main(proto_cli).await?; - } Some(Subcommand::Completion(completion_cli)) => { print_completion(completion_cli); } diff --git a/codex-rs/cli/src/proto.rs b/codex-rs/cli/src/proto.rs deleted file mode 100644 index 623edca5..00000000 --- a/codex-rs/cli/src/proto.rs +++ /dev/null @@ -1,133 +0,0 @@ -use std::io::IsTerminal; - -use clap::Parser; -use codex_common::CliConfigOverrides; -use codex_core::AuthManager; -use codex_core::ConversationManager; -use codex_core::NewConversation; -use codex_core::config::Config; -use codex_core::config::ConfigOverrides; -use codex_core::protocol::Event; -use codex_core::protocol::EventMsg; -use codex_core::protocol::Submission; -use tokio::io::AsyncBufReadExt; -use tokio::io::BufReader; -use tracing::error; -use tracing::info; - -#[derive(Debug, Parser)] -pub struct ProtoCli { - #[clap(skip)] - pub config_overrides: CliConfigOverrides, -} - -pub async fn run_main(opts: ProtoCli) -> anyhow::Result<()> { - if std::io::stdin().is_terminal() { - anyhow::bail!("Protocol mode expects stdin to be a pipe, not a terminal"); - } - - tracing_subscriber::fmt() - .with_writer(std::io::stderr) - .init(); - - let ProtoCli { config_overrides } = opts; - let overrides_vec = config_overrides - .parse_overrides() - .map_err(anyhow::Error::msg)?; - - let config = Config::load_with_cli_overrides(overrides_vec, ConfigOverrides::default())?; - // Use conversation_manager API to start a conversation - let conversation_manager = - ConversationManager::new(AuthManager::shared(config.codex_home.clone())); - let NewConversation { - conversation_id: _, - conversation, - session_configured, - } = conversation_manager.new_conversation(config).await?; - - // Simulate streaming the session_configured event. - let synthetic_event = Event { - // Fake id value. - id: "".to_string(), - msg: EventMsg::SessionConfigured(session_configured), - }; - let session_configured_event = match serde_json::to_string(&synthetic_event) { - Ok(s) => s, - Err(e) => { - error!("Failed to serialize session_configured: {e}"); - return Err(anyhow::Error::from(e)); - } - }; - println!("{session_configured_event}"); - - // Task that reads JSON lines from stdin and forwards to Submission Queue - let sq_fut = { - let conversation = conversation.clone(); - async move { - let stdin = BufReader::new(tokio::io::stdin()); - let mut lines = stdin.lines(); - loop { - let result = tokio::select! { - _ = tokio::signal::ctrl_c() => { - break - }, - res = lines.next_line() => res, - }; - - match result { - Ok(Some(line)) => { - let line = line.trim(); - if line.is_empty() { - continue; - } - match serde_json::from_str::(line) { - Ok(sub) => { - if let Err(e) = conversation.submit_with_id(sub).await { - error!("{e:#}"); - break; - } - } - Err(e) => { - error!("invalid submission: {e}"); - } - } - } - _ => { - info!("Submission queue closed"); - break; - } - } - } - } - }; - - // Task that reads events from the agent and prints them as JSON lines to stdout - let eq_fut = async move { - loop { - let event = tokio::select! { - _ = tokio::signal::ctrl_c() => break, - event = conversation.next_event() => event, - }; - match event { - Ok(event) => { - let event_str = match serde_json::to_string(&event) { - Ok(s) => s, - Err(e) => { - error!("Failed to serialize event: {e}"); - continue; - } - }; - println!("{event_str}"); - } - Err(e) => { - error!("{e:#}"); - break; - } - } - } - info!("Event queue closed"); - }; - - tokio::join!(sq_fut, eq_fut); - Ok(()) -}