Compare commits

...

1 Commits

Author SHA1 Message Date
Joey Pereira
96cece3ac5 include session ID on non-interactive surfaces
- on the JSON mode, include it on the initial JSON config summary
  - on non-interactive mode, include it alongside human-readable info
2025-09-18 08:17:10 -07:00
4 changed files with 37 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ use std::path::Path;
use codex_core::config::Config;
use codex_core::protocol::Event;
use codex_core::protocol::SessionConfiguredEvent;
pub(crate) enum CodexStatus {
Running,
@@ -11,7 +12,12 @@ pub(crate) enum CodexStatus {
pub(crate) trait EventProcessor {
/// Print summary of effective configuration and user prompt.
fn print_config_summary(&mut self, config: &Config, prompt: &str);
fn print_config_summary(
&mut self,
config: &Config,
prompt: &str,
session_configured: &SessionConfiguredEvent,
);
/// Handle a single event emitted by the agent.
fn process_event(&mut self, event: Event) -> CodexStatus;

View File

@@ -141,7 +141,12 @@ impl EventProcessor for EventProcessorWithHumanOutput {
/// Print a concise summary of the effective configuration that will be used
/// for the session. This mirrors the information shown in the TUI welcome
/// screen.
fn print_config_summary(&mut self, config: &Config, prompt: &str) {
fn print_config_summary(
&mut self,
config: &Config,
prompt: &str,
session_configured: &SessionConfiguredEvent,
) {
const VERSION: &str = env!("CARGO_PKG_VERSION");
ts_println!(
self,
@@ -149,7 +154,8 @@ impl EventProcessor for EventProcessorWithHumanOutput {
VERSION
);
let entries = create_config_summary_entries(config);
let mut entries = create_config_summary_entries(config);
entries.insert(0, ("session id", session_configured.session_id.to_string()));
for (key, value) in entries {
println!("{} {}", format!("{key}:").style(self.bold), value);

View File

@@ -4,6 +4,7 @@ use std::path::PathBuf;
use codex_core::config::Config;
use codex_core::protocol::Event;
use codex_core::protocol::EventMsg;
use codex_core::protocol::SessionConfiguredEvent;
use codex_core::protocol::TaskCompleteEvent;
use serde_json::json;
@@ -23,11 +24,20 @@ impl EventProcessorWithJsonOutput {
}
impl EventProcessor for EventProcessorWithJsonOutput {
fn print_config_summary(&mut self, config: &Config, prompt: &str) {
let entries = create_config_summary_entries(config)
fn print_config_summary(
&mut self,
config: &Config,
prompt: &str,
session_configured: &SessionConfiguredEvent,
) {
let mut entries = create_config_summary_entries(config)
.into_iter()
.map(|(key, value)| (key.to_string(), value))
.collect::<HashMap<String, String>>();
entries.insert(
"session_id".to_string(),
session_configured.session_id.to_string(),
);
#[expect(clippy::expect_used)]
let config_json =
serde_json::to_string(&entries).expect("Failed to serialize config summary to JSON");

View File

@@ -189,10 +189,6 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
.map_err(|e| anyhow::anyhow!("OSS setup failed: {e}"))?;
}
// Print the effective configuration and prompt so users can see what Codex
// is using.
event_processor.print_config_summary(&config, &prompt);
if !skip_git_repo_check && get_git_repo_root(&config.cwd.to_path_buf()).is_none() {
eprintln!("Not inside a trusted directory and --skip-git-repo-check was not specified.");
std::process::exit(1);
@@ -218,13 +214,21 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
)
.await?
} else {
conversation_manager.new_conversation(config).await?
conversation_manager
.new_conversation(config.clone())
.await?
}
} else {
conversation_manager.new_conversation(config).await?
conversation_manager
.new_conversation(config.clone())
.await?
};
info!("Codex initialized with event: {session_configured:?}");
// Print the effective configuration and prompt so users can see what Codex
// is using.
event_processor.print_config_summary(&config, &prompt, &session_configured);
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel::<Event>();
{
let conversation = conversation.clone();