This commit is contained in:
Ahmed Ibrahim
2026-01-05 19:38:23 -08:00
parent 284dc5c724
commit 91bc7fc5fd
9 changed files with 1075 additions and 8 deletions
+26 -3
View File
@@ -412,12 +412,24 @@ impl ChatWidget {
let initial_messages = event.initial_messages.clone();
let model_for_header = event.model.clone();
self.set_model(&model_for_header);
self.add_to_history(history_cell::new_session_info(
let session_info = history_cell::new_session_info(
&self.config,
&model_for_header,
event,
self.show_welcome_banner,
));
);
let is_startup_header_active = self.active_cell.as_ref().is_some_and(|cell| {
cell.as_any()
.downcast_ref::<history_cell::StartupSessionHeaderHistoryCell>()
.is_some()
});
if is_startup_header_active {
// Replace the startup placeholder header instead of duplicating it.
self.active_cell = Some(Box::new(session_info));
self.flush_active_cell();
} else {
self.add_to_history(session_info);
}
if let Some(messages) = initial_messages {
self.replay_initial_messages(messages);
}
@@ -1302,6 +1314,7 @@ impl ChatWidget {
model,
} = common;
let mut config = config;
let startup_dir = config.cwd.clone();
// `model` is an optional override provided by the app. Avoid clobbering the configured
// model with an empty string during startup; that would propagate to core and render as a
// blank model in the session header (/model current label, etc).
@@ -1326,7 +1339,9 @@ impl ChatWidget {
animations_enabled: config.animations,
skills: None,
}),
active_cell: None,
active_cell: Some(Box::new(
history_cell::StartupSessionHeaderHistoryCell::new(startup_dir),
)),
config,
model: model.clone(),
auth_manager,
@@ -1714,6 +1729,14 @@ impl ChatWidget {
fn flush_active_cell(&mut self) {
if let Some(active) = self.active_cell.take() {
if active
.as_ref()
.as_any()
.downcast_ref::<history_cell::StartupSessionHeaderHistoryCell>()
.is_some()
{
return;
}
self.needs_final_message_separator = true;
self.app_event_tx.send(AppEvent::InsertHistoryCell(active));
}
@@ -0,0 +1,11 @@
---
source: tui2/src/chatwidget/tests.rs
assertion_line: 160
expression: active_blob(&chat)
---
╭───────────────────────────────────────╮
│ >_ OpenAI Codex (v0.0.0) │
│ │
│ model: loading /model to change │
│ directory: ~/code/codex/codex-rs/tui2 │
╰───────────────────────────────────────╯
+57
View File
@@ -150,6 +150,63 @@ async fn resumed_initial_messages_render_history() {
);
}
#[tokio::test]
async fn startup_header_renders_in_active_cell_before_session_configured_snapshot() {
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(None).await;
let startup_dir = chat.config.cwd.clone();
chat.active_cell = Some(Box::new(
crate::history_cell::StartupSessionHeaderHistoryCell::new(startup_dir),
));
assert_snapshot!("startup_header_active_cell", active_blob(&chat));
}
#[tokio::test]
async fn startup_header_is_replaced_on_session_configured() {
let (mut chat, mut rx, _ops) = make_chatwidget_manual(None).await;
let startup_dir = chat.config.cwd.clone();
chat.active_cell = Some(Box::new(
crate::history_cell::StartupSessionHeaderHistoryCell::new(startup_dir),
));
let conversation_id = ConversationId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = codex_core::protocol::SessionConfiguredEvent {
session_id: conversation_id,
model: "test-model".to_string(),
model_provider_id: "test-provider".to_string(),
approval_policy: AskForApproval::Never,
sandbox_policy: SandboxPolicy::ReadOnly,
cwd: PathBuf::from("/home/user/project"),
reasoning_effort: Some(ReasoningEffortConfig::default()),
history_log_id: 0,
history_entry_count: 0,
initial_messages: None,
rollout_path: rollout_file.path().to_path_buf(),
};
chat.handle_codex_event(Event {
id: "initial".into(),
msg: EventMsg::SessionConfigured(configured),
});
assert!(chat.active_cell.is_none());
let cells = drain_insert_history(&mut rx);
let merged_lines = cells
.iter()
.flat_map(|lines| {
lines
.iter()
.flat_map(|line| line.spans.iter())
.map(|span| span.content.clone())
})
.collect::<String>();
assert!(
merged_lines.contains("test-model"),
"expected resolved model to be recorded in history cell, got:\n{merged_lines}",
);
}
/// Entering review mode uses the hint provided by the review request.
#[tokio::test]
async fn entered_review_mode_uses_request_hint() {
+43 -1
View File
@@ -757,6 +757,7 @@ pub(crate) fn new_session_info(
// Header box rendered as history (so it appears at the very top)
let header = SessionHeaderHistoryCell::new(
model.clone(),
Style::default(),
reasoning_effort,
config.cwd.clone(),
CODEX_CLI_VERSION,
@@ -825,6 +826,7 @@ pub(crate) fn new_user_prompt(message: String) -> UserHistoryCell {
struct SessionHeaderHistoryCell {
version: &'static str,
model: String,
model_style: Style,
reasoning_effort: Option<ReasoningEffortConfig>,
directory: PathBuf,
}
@@ -832,6 +834,7 @@ struct SessionHeaderHistoryCell {
impl SessionHeaderHistoryCell {
fn new(
model: String,
model_style: Style,
reasoning_effort: Option<ReasoningEffortConfig>,
directory: PathBuf,
version: &'static str,
@@ -839,6 +842,7 @@ impl SessionHeaderHistoryCell {
Self {
version,
model,
model_style,
reasoning_effort,
directory,
}
@@ -911,7 +915,7 @@ impl HistoryCell for SessionHeaderHistoryCell {
let reasoning_label = self.reasoning_label();
let mut model_spans: Vec<Span<'static>> = vec![
Span::from(format!("{model_label} ")).dim(),
Span::from(self.model.clone()),
Span::from(self.model.clone()).set_style(self.model_style),
];
if let Some(reasoning) = reasoning_label {
model_spans.push(Span::from(" "));
@@ -939,6 +943,43 @@ impl HistoryCell for SessionHeaderHistoryCell {
}
}
/// Startup-only session header shown in the active cell before SessionConfigured arrives.
///
/// This is a transient UI element and is excluded from transcripts/copy.
#[derive(Debug)]
pub(crate) struct StartupSessionHeaderHistoryCell(SessionHeaderHistoryCell);
impl StartupSessionHeaderHistoryCell {
pub(crate) fn new(directory: PathBuf) -> Self {
let inner = SessionHeaderHistoryCell::new(
"loading".to_string(),
Style::default().dim().italic(),
None,
directory,
CODEX_CLI_VERSION,
);
Self(inner)
}
}
impl HistoryCell for StartupSessionHeaderHistoryCell {
fn display_lines(&self, width: u16) -> Vec<Line<'static>> {
self.0.display_lines(width)
}
fn desired_height(&self, width: u16) -> u16 {
self.0.desired_height(width)
}
fn transcript_lines(&self, _width: u16) -> Vec<Line<'static>> {
Vec::new()
}
fn desired_transcript_height(&self, _width: u16) -> u16 {
0
}
}
#[derive(Debug)]
pub(crate) struct CompositeHistoryCell {
parts: Vec<Box<dyn HistoryCell>>,
@@ -2023,6 +2064,7 @@ mod tests {
fn session_header_includes_reasoning_level_when_present() {
let cell = SessionHeaderHistoryCell::new(
"gpt-4o".to_string(),
Style::default(),
Some(ReasoningEffortConfig::High),
std::env::temp_dir(),
"test",