Skip to content
Prev Previous commit
Next Next commit
review
  • Loading branch information
aibrahim-oai committed Sep 15, 2025
commit 8ba7fcc6d83caa408f5749c70858dd856cf50986
2 changes: 1 addition & 1 deletion codex-rs/tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl App {
self.on_update_reasoning_effort(effort);
}
AppEvent::UpdateModel(model) => {
self.chat_widget.set_model(model.clone());
self.chat_widget.set_model(&model);
self.config.model = model.clone();
if let Some(family) = find_family_for_model(&model) {
self.config.model_family = family;
Expand Down
23 changes: 6 additions & 17 deletions codex-rs/tui/src/chatwidget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl ChatWidget {
if let Some(messages) = initial_messages {
self.replay_initial_messages(messages);
}
let _ = self.session_header.set_model(model_for_header);
let _ = self.session_header.set_model(&model_for_header);
self.add_to_history(history_cell::new_session_info(
&self.config,
event,
Expand Down Expand Up @@ -665,11 +665,7 @@ impl ChatWidget {
}),
active_exec_cell: None,
config: config.clone(),
session_header: SessionHeader::new(
config.model.clone(),
config.cwd.clone(),
crate::version::CODEX_CLI_VERSION,
),
session_header: SessionHeader::new(config.model.clone()),
initial_user_message: create_initial_user_message(
initial_prompt.unwrap_or_default(),
initial_images,
Expand Down Expand Up @@ -722,11 +718,7 @@ impl ChatWidget {
}),
active_exec_cell: None,
config: config.clone(),
session_header: SessionHeader::new(
config.model.clone(),
config.cwd.clone(),
crate::version::CODEX_CLI_VERSION,
),
session_header: SessionHeader::new(config.model.clone()),
initial_user_message: create_initial_user_message(
initial_prompt.unwrap_or_default(),
initial_images,
Expand Down Expand Up @@ -1305,12 +1297,9 @@ impl ChatWidget {
}

/// Set the model in the widget's config copy.
pub(crate) fn set_model(&mut self, model: String) {
let header_changed = self.session_header.set_model(model.clone());
self.config.model = model;
if header_changed {
self.request_redraw();
}
pub(crate) fn set_model(&mut self, model: &str) {
self.session_header.set_model(model);
self.config.model = model.to_string();
}

pub(crate) fn add_info_message(&mut self, message: String, hint: Option<String>) {
Expand Down
15 changes: 5 additions & 10 deletions codex-rs/tui/src/chatwidget/session_header.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use std::path::PathBuf;

pub(crate) struct SessionHeader {
model: String,
}

impl SessionHeader {
// Keep signature to avoid changing call sites; underscore params silence warnings.
pub(crate) fn new(model: String, _directory: PathBuf, _version: &'static str) -> Self {
pub(crate) fn new(model: String) -> Self {
Self { model }
}

pub(crate) fn set_model(&mut self, model: String) -> bool {
if self.model == model {
false
} else {
self.model = model;
true
/// Updates the header's model text.
pub(crate) fn set_model(&mut self, model: &str) {
if self.model != model {
self.model = model.to_string();
}
}
}
10 changes: 3 additions & 7 deletions codex-rs/tui/src/chatwidget/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,7 @@ fn make_chatwidget_manual() -> (
bottom_pane: bottom,
active_exec_cell: None,
config: cfg.clone(),
session_header: SessionHeader::new(
cfg.model.clone(),
cfg.cwd.clone(),
crate::version::CODEX_CLI_VERSION,
),
session_header: SessionHeader::new(cfg.model.clone()),
initial_user_message: None,
token_info: None,
stream: StreamController::new(cfg),
Expand Down Expand Up @@ -781,10 +777,10 @@ async fn binary_size_transcript_snapshot() {
// 'thinking' header if present, and start from the first non-empty content line
// that follows. This keeps the snapshot stable across sessions.
const MARKER_PREFIX: &str =
" Describe a task to get started or try one of the following commands:";
"Describe a task to get started or try one of the following commands:";
let last_marker_line_idx = lines
.iter()
.rposition(|l| l.starts_with(MARKER_PREFIX))
.rposition(|l| l.trim_start().starts_with(MARKER_PREFIX))
.expect("marker not found in visible output");
// Prefer the first assistant content line (blockquote '>' prefix) after the marker;
// fallback to the first non-empty, non-'thinking' line.
Expand Down
Loading