diff --git a/codex-rs/tui/src/app/session_lifecycle.rs b/codex-rs/tui/src/app/session_lifecycle.rs index 2711f310ba..1a8422ec1f 100644 --- a/codex-rs/tui/src/app/session_lifecycle.rs +++ b/codex-rs/tui/src/app/session_lifecycle.rs @@ -684,8 +684,8 @@ impl App { chat_widget.inherit_security_setup(&mut self.chat_widget); } chat_widget - .mention_usage_mut() - .inherit(self.chat_widget.mention_usage_mut()); + .picker_usage_mut() + .inherit(self.chat_widget.picker_usage_mut()); for (thread_id, entry) in self.agent_navigation.ordered_threads() { chat_widget.set_collab_agent_metadata( thread_id, diff --git a/codex-rs/tui/src/app/startup.rs b/codex-rs/tui/src/app/startup.rs index 36990933e5..a9f649e8e7 100644 --- a/codex-rs/tui/src/app/startup.rs +++ b/codex-rs/tui/src/app/startup.rs @@ -2056,7 +2056,7 @@ See the Codex keymap documentation for supported actions and examples." for cancellation in app.pending_thread_titles.values() { cancellation.cancel(); } - app.chat_widget.mention_usage_mut().flush().await; + app.chat_widget.picker_usage_mut().flush().await; // Closing a remote or embedded connection can abandon an outstanding archive. let archive_warnings = app .finish_pending_archives(tokio::time::Instant::now() + Duration::from_secs(/*secs*/ 5)) diff --git a/codex-rs/tui/src/app/tests/disconnect_tests.rs b/codex-rs/tui/src/app/tests/disconnect_tests.rs index de4223e5fe..cd0a7bddb2 100644 --- a/codex-rs/tui/src/app/tests/disconnect_tests.rs +++ b/codex-rs/tui/src/app/tests/disconnect_tests.rs @@ -223,6 +223,16 @@ async fn lost_mutation_reply_preserves_work_without_resubmitting() -> Result<()> for command in ["/exit", "/quit", "/q"] { app.chat_widget .restore_user_message_to_composer(command.into()); + if command == "/q" { + app.handle_tui_event(&mut tui, &mut session, TuiEvent::Key(KeyCode::Enter.into())) + .await?; + assert!( + !std::iter::from_fn(|| events.try_recv().ok()) + .any(|e| matches!(e, AppEvent::Exit(_))) + ); + app.handle_tui_event(&mut tui, &mut session, TuiEvent::Key(KeyCode::Down.into())) + .await?; + } app.handle_tui_event(&mut tui, &mut session, TuiEvent::Key(KeyCode::Enter.into())) .await?; let exit = std::iter::from_fn(|| events.try_recv().ok()) diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index 151c1c60c7..89005aec82 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -37,7 +37,8 @@ //! By default, `@` lists plugins, filesystem entries, and skills. Skills are hidden when their //! owning plugin is listed. `$` lists individual skills and apps, but not plugins. //! Disabling `mentions_v2` restores file-only `@` search and adds plugins back to `$`. -//! Confirmed `$` picker selections inform future ordering within each match tier. +//! Confirmed `$` selections and dispatched slash commands rank future matches within each +//! tier using separate rolling usage windows. //! A cached plugin skill keeps its ranking when its installed version changes. //! //! Ordinary prompt undo records the complete draft before each edit. Contiguous typing shares a @@ -389,11 +390,11 @@ use super::footer::render_footer_line; use super::footer::reset_mode_after_activity; use super::footer::side_conversation_context_line; use super::footer::toggle_shortcut_mode; -use super::mention_usage::MentionUsage; use super::mentions_v2::MentionV2Popup; use super::mentions_v2::MentionV2Selection; use super::paste_burst::CharDecision; use super::paste_burst::PasteBurst; +use super::picker_usage::PickerUsage; use super::prompt_args::parse_slash_name; use super::prompt_args::slash_args_elements; use super::skill_popup::MentionItem; @@ -657,7 +658,7 @@ impl ChatComposerConfig { pub(crate) struct ChatComposer { draft: DraftState, popups: PopupState, - pub(super) mention_usage: MentionUsage, + pub(super) picker_usage: PickerUsage, app_event_tx: AppEventSender, history: ChatComposerHistory, pub(super) command_center_enabled: bool, @@ -803,7 +804,7 @@ impl ChatComposer { let mut this = Self { draft: DraftState::new(), popups: PopupState::default(), - mention_usage: MentionUsage::default(), + picker_usage: PickerUsage::default(), app_event_tx, history: ChatComposerHistory::new(), command_center_enabled: false, @@ -2410,7 +2411,7 @@ impl ChatComposer { { self.insert_selected_mention(target.range, &insert_text, path.as_deref()); if let Some(path) = path { - self.mention_usage.record(&path); + self.picker_usage.mentions.record(&path); } } self.popups.active = ActivePopup::None; @@ -4250,9 +4251,11 @@ impl ChatComposer { if is_editing_slash_command_name && let Some(command_filter_text) = command_filter_text.as_deref() { - let command_popup = self - .slash_input() - .command_popup(command_filter_text, disconnected); + let command_popup = self.slash_input().command_popup( + command_filter_text, + disconnected, + &self.picker_usage.commands, + ); self.popups.active = ActivePopup::Command(command_popup); } } @@ -4332,7 +4335,8 @@ impl ChatComposer { popup.set_mentions(mentions); } _ => { - let mut popup = SkillPopup::new(mentions).with_frequencies(&self.mention_usage); + let mut popup = + SkillPopup::new(mentions).with_frequencies(&self.picker_usage.mentions); popup.set_query(&query); self.popups.active = ActivePopup::Skill(popup); } @@ -7291,7 +7295,7 @@ mod tests { "skill_popup_prefers_confirmed_selections_within_match_tier", /*enhanced_keys_supported*/ false, |composer| { - composer.mention_usage = MentionUsage::load( + composer.picker_usage = PickerUsage::load( home.path(), codex_config::types::HistoryPersistence::SaveAll, ); diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/slash_input.rs b/codex-rs/tui/src/bottom_pane/chat_composer/slash_input.rs index c4f0eedaa0..317ba3bbbe 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer/slash_input.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer/slash_input.rs @@ -172,7 +172,12 @@ impl<'a> SlashInput<'a> { has_slash_command_prefix(name, self.command_flags, self.service_tier_commands) } - pub(super) fn command_popup(&self, filter_text: &str, disconnected: bool) -> CommandPopup { + pub(super) fn command_popup( + &self, + filter_text: &str, + disconnected: bool, + usage: &crate::bottom_pane::picker_usage::SelectionHistory, + ) -> CommandPopup { let mut command_popup = CommandPopup::new( CommandPopupFlags { disconnected, @@ -189,7 +194,8 @@ impl<'a> SlashInput<'a> { side_conversation_active: self.command_flags.side_conversation_active, }, self.service_tier_commands.to_vec(), - ); + ) + .with_frequencies(usage.frequencies()); command_popup.on_composer_text_change(filter_text.to_string()); command_popup } diff --git a/codex-rs/tui/src/bottom_pane/command_popup.rs b/codex-rs/tui/src/bottom_pane/command_popup.rs index a2a7f36386..8ffd0f2d90 100644 --- a/codex-rs/tui/src/bottom_pane/command_popup.rs +++ b/codex-rs/tui/src/bottom_pane/command_popup.rs @@ -1,3 +1,6 @@ +use std::cmp::Reverse; +use std::collections::HashMap; + use ratatui::buffer::Buffer; use ratatui::layout::Rect; use ratatui::widgets::WidgetRef; @@ -21,7 +24,10 @@ use crate::slash_command::SlashCommand; // Hide alias commands in the default popup list so each unique action appears once. // `quit` is an alias of `exit`, and `btw` is an alias of `side`, so we skip // those aliases here. -const ALIAS_COMMANDS: &[SlashCommand] = &[SlashCommand::Quit, SlashCommand::Btw]; +const ALIAS_COMMANDS: &[(SlashCommand, SlashCommand)] = &[ + (SlashCommand::Quit, SlashCommand::Exit), + (SlashCommand::Btw, SlashCommand::Side), +]; const COMMAND_COLUMN_WIDTH: ColumnWidthConfig = ColumnWidthConfig::new( ColumnWidthMode::AutoAllRows, /*name_column_width*/ None, @@ -78,6 +84,27 @@ impl From for BuiltinCommandFlags { } impl CommandPopup { + /// Stable sorting keeps menu order for ties. Filtering still prioritizes exact matches + /// and available commands. + pub(super) fn with_frequencies(mut self, mut frequencies: HashMap) -> Self { + for (alias, primary) in ALIAS_COMMANDS { + let count = frequencies + .get(alias.command()) + .copied() + .unwrap_or_default() + + frequencies + .get(primary.command()) + .copied() + .unwrap_or_default(); + frequencies.insert(alias.command().to_owned(), count); + frequencies.insert(primary.command().to_owned(), count); + } + self.commands.sort_by_key(|item| { + Reverse(frequencies.get(item.command()).copied().unwrap_or_default()) + }); + self + } + pub(crate) fn new( flags: CommandPopupFlags, service_tier_commands: Vec, @@ -130,7 +157,16 @@ impl CommandPopup { } self.command_filter = Some(filter.to_owned()); self.state.reset(); - self.state.clamp_selection(self.filtered_items().len()); + let items = self.filtered_items(); + // Shutdown commands require a full name or explicit navigation. + if let Some(CommandItem::Builtin( + cmd @ (SlashCommand::Exit | SlashCommand::Quit | SlashCommand::Logout), + )) = items.first() + && !filter.eq_ignore_ascii_case(cmd.command()) + { + return; + } + self.state.clamp_selection(items.len()); } /// Determine the preferred height of the popup for a given width. @@ -147,15 +183,14 @@ impl CommandPopup { ) } - /// Compute exact/prefix matches over built-in commands and user prompts, - /// paired with optional highlight indices. Preserves the original - /// presentation order for built-ins and prompts. + /// Preserve usage order within each match tier and compute highlight indices. fn filtered(&self) -> Vec<(CommandItem, Option>)> { let filter = self.command_filter.as_deref().unwrap_or_default(); let mut out: Vec<(CommandItem, Option>)> = Vec::new(); if filter.is_empty() { for command in self.commands.iter() { - if matches!(command, CommandItem::Builtin(cmd) if ALIAS_COMMANDS.contains(cmd)) { + if matches!(command, CommandItem::Builtin(cmd) if ALIAS_COMMANDS.iter().any(|(alias, _)| alias == cmd)) + { continue; } if self.unavailable_reason(command).is_some() { @@ -610,6 +645,34 @@ mod tests { ); } + #[test] + fn ranked_shutdown_commands_require_explicit_selection() { + let mut popup = CommandPopup::new(CommandPopupFlags::default(), Vec::new()) + .with_frequencies(HashMap::from([("quit".into(), 2), ("btw".into(), 1)])); + popup.on_composer_text_change("/".into()); + assert_eq!(popup.selected_item(), None); + assert!(popup.blocks_submit_fallback()); + let rows = popup.rows_from_matches(popup.filtered()); + let labels = rows + .iter() + .take(3) + .map(|row| format!("{}{}", row.name_prefix_spans[0].content, row.name)) + .collect::>(); + insta::assert_snapshot!(format!("{labels:?}"), @r#"[" /exit", " /side", " /model"]"#); + popup.move_down(); + assert_eq!( + popup.selected_item(), + Some(CommandItem::Builtin(SlashCommand::Exit)) + ); + popup.on_composer_text_change("/logo".into()); + assert_eq!(popup.selected_item(), None); + popup.on_composer_text_change("/logout".into()); + assert_eq!( + popup.selected_item(), + Some(CommandItem::Builtin(SlashCommand::Logout)) + ); + } + #[test] fn quit_hidden_in_empty_filter_but_shown_for_prefix() { let mut popup = CommandPopup::new(CommandPopupFlags::default(), Vec::new()); diff --git a/codex-rs/tui/src/bottom_pane/mod.rs b/codex-rs/tui/src/bottom_pane/mod.rs index cc0463e255..6da8e83df1 100644 --- a/codex-rs/tui/src/bottom_pane/mod.rs +++ b/codex-rs/tui/src/bottom_pane/mod.rs @@ -163,17 +163,17 @@ mod file_search_popup; mod footer; mod list_selection_view; mod memories_settings_view; -mod mention_usage; -pub(crate) use mention_usage::MentionUsage; mod mentions_v2; mod picker_presets; mod picker_rows; mod picker_style; +mod picker_usage; mod shortcut_hud; mod shortcut_overlay; pub(crate) use picker_style::active_tab_style; pub(crate) use picker_style::render_scroll_indicators; pub(crate) use picker_style::selection_style; +pub(crate) use picker_usage::PickerUsage; pub(crate) use shortcut_hud::ShortcutHud; pub(crate) mod prompt_args; mod selection_picker_layout; @@ -373,16 +373,16 @@ pub(crate) struct BottomPaneParams { } impl BottomPane { - pub(crate) fn set_mention_usage_home( + pub(crate) fn set_picker_usage_home( &mut self, codex_home: &std::path::Path, persistence: codex_config::types::HistoryPersistence, ) { - self.composer.mention_usage = MentionUsage::load(codex_home, persistence); + self.composer.picker_usage = PickerUsage::load(codex_home, persistence); } - pub(crate) fn mention_usage_mut(&mut self) -> &mut MentionUsage { - &mut self.composer.mention_usage + pub(crate) fn picker_usage_mut(&mut self) -> &mut PickerUsage { + &mut self.composer.picker_usage } pub fn new(params: BottomPaneParams) -> Self { diff --git a/codex-rs/tui/src/bottom_pane/mention_usage.rs b/codex-rs/tui/src/bottom_pane/picker_usage.rs similarity index 77% rename from codex-rs/tui/src/bottom_pane/mention_usage.rs rename to codex-rs/tui/src/bottom_pane/picker_usage.rs index f06c63cffc..e9fe9490df 100644 --- a/codex-rs/tui/src/bottom_pane/mention_usage.rs +++ b/codex-rs/tui/src/bottom_pane/picker_usage.rs @@ -1,4 +1,4 @@ -//! Locally remembers a bounded window of confirmed `$` picker selections. +//! Locally remembers separate bounded windows of confirmed mentions and slash commands. //! //! The active composer updates its window immediately and carries it across compatible widget //! replacements. Background workers serialize writes, and a bounded file-lock wait merges @@ -22,7 +22,7 @@ use tokio::task::JoinHandle; const HISTORY_LIMIT: usize = 50; const MAX_FILE_BYTES: u64 = 1024 * 1024; -const FILE_NAME: &str = "mention_usage.json"; +const MENTION_FILE: &str = "mention_usage.json"; const LOCK_TIMEOUT: Duration = Duration::from_millis(100); const LOCK_RETRY_INTERVAL: Duration = Duration::from_millis(10); const FLUSH_TIMEOUT: Duration = Duration::from_secs(1); @@ -34,19 +34,49 @@ struct Storage { } #[derive(Default)] -pub(crate) struct MentionUsage { +pub(crate) struct PickerUsage { + pub(super) mentions: SelectionHistory, + pub(super) commands: SelectionHistory, +} + +impl PickerUsage { + pub(crate) fn record_command(&mut self, name: &str) { + self.commands.record(name); + } + + pub(super) fn load(codex_home: &Path, persistence: HistoryPersistence) -> Self { + Self { + mentions: SelectionHistory::load(codex_home.join(MENTION_FILE), persistence), + commands: SelectionHistory::load( + codex_home.join("slash_command_usage.json"), + persistence, + ), + } + } + + pub(crate) fn inherit(&mut self, previous: &mut Self) { + self.mentions.inherit(&mut previous.mentions); + self.commands.inherit(&mut previous.commands); + } + + pub(crate) async fn flush(&mut self) { + tokio::join!(self.mentions.flush(), self.commands.flush()); + } +} + +#[derive(Default)] +pub(super) struct SelectionHistory { recent: VecDeque, storage: Option, writer: Option>, workers: Vec>, } -impl MentionUsage { - pub(super) fn load(codex_home: &Path, persistence: HistoryPersistence) -> Self { - let path = codex_home.join(FILE_NAME); +impl SelectionHistory { + fn load(path: PathBuf, persistence: HistoryPersistence) -> Self { let recent = match persistence { HistoryPersistence::SaveAll => read_recent(&path).unwrap_or_else(|error| { - tracing::debug!(%error, "could not load mention preferences"); + tracing::debug!(%error, "could not load picker preferences"); VecDeque::new() }), HistoryPersistence::None => VecDeque::new(), @@ -75,7 +105,7 @@ impl MentionUsage { let drain = async { for worker in &mut workers { if let Err(error) = worker.await { - tracing::debug!(%error, "mention preference writer stopped"); + tracing::debug!(%error, "picker preference writer stopped"); } } }; @@ -83,7 +113,7 @@ impl MentionUsage { for worker in workers { worker.abort(); } - tracing::debug!("timed out saving mention preferences"); + tracing::debug!("timed out saving picker preferences"); } } @@ -124,10 +154,10 @@ impl MentionUsage { { Ok(Ok(())) => {} Ok(Err(error)) => { - tracing::debug!(%error, "could not save mention preferences"); + tracing::debug!(%error, "could not save picker preferences"); } Err(error) => { - tracing::debug!(%error, "mention preference writer stopped"); + tracing::debug!(%error, "picker preference writer stopped"); } } } @@ -135,7 +165,7 @@ impl MentionUsage { sender }); if writer.try_send(identity.to_owned()).is_err() { - tracing::debug!("could not queue mention preference update"); + tracing::debug!("could not queue picker preference update"); } } } @@ -154,7 +184,7 @@ fn read_recent(path: &Path) -> io::Result> { Err(error) => return Err(error), }; if file.metadata()?.len() > MAX_FILE_BYTES { - return Err(io::Error::other("mention preferences exceed size limit")); + return Err(io::Error::other("picker preferences exceed size limit")); } let mut recent: VecDeque = match serde_json::from_reader(file) { Ok(recent) => recent, @@ -185,11 +215,11 @@ fn persist_selection(path: &Path, identity: String) -> io::Result<()> { append_recent(&mut recent, identity); let contents = serde_json::to_string(&recent)?; if contents.len() as u64 > MAX_FILE_BYTES { - return Err(io::Error::other("mention preferences exceed size limit")); + return Err(io::Error::other("picker preferences exceed size limit")); } write_atomically(path, &contents) } #[cfg(test)] -#[path = "mention_usage_tests.rs"] +#[path = "picker_usage_tests.rs"] mod tests; diff --git a/codex-rs/tui/src/bottom_pane/mention_usage_tests.rs b/codex-rs/tui/src/bottom_pane/picker_usage_tests.rs similarity index 54% rename from codex-rs/tui/src/bottom_pane/mention_usage_tests.rs rename to codex-rs/tui/src/bottom_pane/picker_usage_tests.rs index 5e17c2fa63..551fa96191 100644 --- a/codex-rs/tui/src/bottom_pane/mention_usage_tests.rs +++ b/codex-rs/tui/src/bottom_pane/picker_usage_tests.rs @@ -4,15 +4,24 @@ use pretty_assertions::assert_eq; #[tokio::test] async fn selection_frequency_persists_after_handoff_and_flush() { let home = tempfile::tempdir().expect("temporary home"); - let mut usage = MentionUsage::load(home.path(), HistoryPersistence::SaveAll); - usage.record("skill://status"); - usage.record("skill://status"); - let mut replacement = MentionUsage::load(home.path(), HistoryPersistence::SaveAll); + let mut usage = PickerUsage::load(home.path(), HistoryPersistence::SaveAll); + usage.mentions.record("skill://status"); + usage.mentions.record("skill://status"); + usage.commands.record("status"); + let mut replacement = PickerUsage::load(home.path(), HistoryPersistence::SaveAll); replacement.inherit(&mut usage); replacement.flush().await; + assert_eq!( + PickerUsage::load(home.path(), HistoryPersistence::SaveAll) + .commands + .frequencies(), + HashMap::from([("status".to_owned(), 1)]) + ); assert_eq!( - MentionUsage::load(home.path(), HistoryPersistence::SaveAll).frequencies(), + PickerUsage::load(home.path(), HistoryPersistence::SaveAll) + .mentions + .frequencies(), HashMap::from([("skill://status".to_owned(), 2)]) ); } @@ -21,17 +30,21 @@ async fn selection_frequency_persists_after_handoff_and_flush() { async fn changing_storage_keeps_usage_separate_and_flushes_prior_writes() { let first_home = tempfile::tempdir().expect("first temporary home"); let second_home = tempfile::tempdir().expect("second temporary home"); - let mut first = MentionUsage::load(first_home.path(), HistoryPersistence::SaveAll); - first.record("skill://first"); - let mut second = MentionUsage::load(second_home.path(), HistoryPersistence::SaveAll); + let mut first = PickerUsage::load(first_home.path(), HistoryPersistence::SaveAll); + first.mentions.record("skill://first"); + let mut second = PickerUsage::load(second_home.path(), HistoryPersistence::SaveAll); second.inherit(&mut first); - second.record("skill://second"); + second.mentions.record("skill://second"); second.flush().await; assert_eq!( ( - MentionUsage::load(first_home.path(), HistoryPersistence::SaveAll).frequencies(), - MentionUsage::load(second_home.path(), HistoryPersistence::SaveAll).frequencies(), + PickerUsage::load(first_home.path(), HistoryPersistence::SaveAll) + .mentions + .frequencies(), + PickerUsage::load(second_home.path(), HistoryPersistence::SaveAll) + .mentions + .frequencies(), ), ( HashMap::from([("skill://first".to_owned(), 1)]), @@ -42,13 +55,13 @@ async fn changing_storage_keeps_usage_separate_and_flushes_prior_writes() { #[test] fn old_selections_expire() { - let mut usage = MentionUsage::default(); - usage.record("skill://status"); + let mut usage = PickerUsage::default(); + usage.mentions.record("skill://status"); for _ in 0..HISTORY_LIMIT { - usage.record("skill://other"); + usage.mentions.record("skill://other"); } assert_eq!( - usage.frequencies(), + usage.mentions.frequencies(), HashMap::from([("skill://other".to_owned(), HISTORY_LIMIT)]) ); } @@ -56,13 +69,15 @@ fn old_selections_expire() { #[test] fn selection_replaces_malformed_history() { let home = tempfile::tempdir().expect("temporary home"); - let path = home.path().join(FILE_NAME); + let path = home.path().join(MENTION_FILE); std::fs::write(&path, "[\"truncated").expect("write malformed history"); persist_selection(&path, "skill://status".to_owned()).expect("persist selection"); assert_eq!( - MentionUsage::load(home.path(), HistoryPersistence::SaveAll).frequencies(), + PickerUsage::load(home.path(), HistoryPersistence::SaveAll) + .mentions + .frequencies(), HashMap::from([("skill://status".to_owned(), 1)]) ); } @@ -70,7 +85,7 @@ fn selection_replaces_malformed_history() { #[test] fn contended_lock_does_not_prevent_later_selections() { let home = tempfile::tempdir().expect("temporary home"); - let path = home.path().join(FILE_NAME); + let path = home.path().join(MENTION_FILE); let lock = File::create(path.with_extension("lock")).expect("create lock file"); lock.lock().expect("hold lock"); assert_eq!( @@ -82,7 +97,9 @@ fn contended_lock_does_not_prevent_later_selections() { drop(lock); persist_selection(&path, "skill://status".to_owned()).expect("persist selection"); assert_eq!( - MentionUsage::load(home.path(), HistoryPersistence::SaveAll).frequencies(), + PickerUsage::load(home.path(), HistoryPersistence::SaveAll) + .mentions + .frequencies(), HashMap::from([("skill://status".to_owned(), 1)]) ); } diff --git a/codex-rs/tui/src/bottom_pane/skill_popup.rs b/codex-rs/tui/src/bottom_pane/skill_popup.rs index d9cd595b0e..25f8db00c8 100644 --- a/codex-rs/tui/src/bottom_pane/skill_popup.rs +++ b/codex-rs/tui/src/bottom_pane/skill_popup.rs @@ -15,8 +15,8 @@ use std::path::Component; use std::path::Path; use std::path::PathBuf; -use super::mention_usage::MentionUsage; use super::picker_rows::render_rows_single_line; +use super::picker_usage::SelectionHistory; use super::popup_consts::MAX_POPUP_ROWS; use super::scroll_state::ScrollState; use super::selection_popup_common::GenericDisplayRow; @@ -110,7 +110,7 @@ impl SkillPopup { } } - pub(super) fn with_frequencies(mut self, usage: &MentionUsage) -> Self { + pub(super) fn with_frequencies(mut self, usage: &SelectionHistory) -> Self { if let Some(home) = usage.codex_home() { let root = home.join(PLUGINS_CACHE_DIR); // Skill discovery returns canonical paths rendered for the app server API. diff --git a/codex-rs/tui/src/chatwidget/constructor.rs b/codex-rs/tui/src/chatwidget/constructor.rs index f85f01c6ba..a1e571a254 100644 --- a/codex-rs/tui/src/chatwidget/constructor.rs +++ b/codex-rs/tui/src/chatwidget/constructor.rs @@ -331,7 +331,7 @@ impl ChatWidget { test_codex_home: None, }; - widget.bottom_pane.set_mention_usage_home( + widget.bottom_pane.set_picker_usage_home( widget.local_settings.codex_home.as_path(), widget.local_settings.history.persistence, ); diff --git a/codex-rs/tui/src/chatwidget/input_restore.rs b/codex-rs/tui/src/chatwidget/input_restore.rs index 14345f888a..76eeb36b08 100644 --- a/codex-rs/tui/src/chatwidget/input_restore.rs +++ b/codex-rs/tui/src/chatwidget/input_restore.rs @@ -7,15 +7,15 @@ use codex_protocol::models::local_image_label_text; use crate::bottom_pane::ComposerDraftSnapshot; use crate::bottom_pane::KillBufferSnapshot; -use crate::bottom_pane::MentionUsage; +use crate::bottom_pane::PickerUsage; use crate::bottom_pane::ShellPrefixHandling; use super::user_messages::remap_colliding_paste_placeholders; use super::*; impl ChatWidget { - pub(crate) fn mention_usage_mut(&mut self) -> &mut MentionUsage { - self.bottom_pane.mention_usage_mut() + pub(crate) fn picker_usage_mut(&mut self) -> &mut PickerUsage { + self.bottom_pane.picker_usage_mut() } pub(crate) fn take_kill_buffer_snapshot(&mut self) -> KillBufferSnapshot { diff --git a/codex-rs/tui/src/chatwidget/slash_dispatch.rs b/codex-rs/tui/src/chatwidget/slash_dispatch.rs index 25f9965578..0f4d135e26 100644 --- a/codex-rs/tui/src/chatwidget/slash_dispatch.rs +++ b/codex-rs/tui/src/chatwidget/slash_dispatch.rs @@ -99,6 +99,7 @@ impl ChatWidget { self.bottom_pane.record_pending_slash_command_history(); return; } + self.picker_usage_mut().record_command(&command.name); self.toggle_service_tier_from_ui(command); self.bottom_pane.record_pending_slash_command_history(); } @@ -272,6 +273,10 @@ impl ChatWidget { return; } + // Bare /cd delegates to the inline argument dispatcher. + if cmd != SlashCommand::Cd { + self.picker_usage_mut().record_command(cmd.command()); + } if source == SlashCommandDispatchSource::Live && cmd.requires_dispatch_validation() { self.bottom_pane .set_composer_text(String::new(), Vec::new(), Vec::new()); @@ -834,6 +839,7 @@ impl ChatWidget { self.dispatch_command_from_source(cmd, source); return; } + self.picker_usage_mut().record_command(cmd.command()); match cmd { SlashCommand::Rc => self.add_error_message( "Open /rc and choose Disable to turn off remote control.".into(), diff --git a/codex-rs/tui/src/chatwidget/tests/slash_commands.rs b/codex-rs/tui/src/chatwidget/tests/slash_commands.rs index ea50b8a860..d2fa5adf3c 100644 --- a/codex-rs/tui/src/chatwidget/tests/slash_commands.rs +++ b/codex-rs/tui/src/chatwidget/tests/slash_commands.rs @@ -229,6 +229,37 @@ async fn slash_recap_requests_generation_for_current_thread() { ); } +#[tokio::test] +async fn queued_and_offline_dispatches_rank_the_next_slash_menu() { + let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + chat.bottom_pane + .set_composer_text("/config".into(), vec![], vec![]); + chat.handle_restricted_key( + KeyCode::Enter.into(), + crate::bottom_pane::RestrictedInputMode::Disconnected, + ); + chat.handle_key_event(KeyCode::Esc.into()); + let select = |chat: &mut ChatWidget, input: &str| { + chat.bottom_pane + .set_composer_text(input.into(), vec![], vec![]); + chat.bottom_pane.handle_key_event(KeyCode::Enter.into()) + }; + assert_eq!( + select(&mut chat, "/"), + InputResult::Command(SlashCommand::Config) + ); + for _ in 0..2 { + chat.submit_queued_slash_prompt(UserMessage::from("/statusline model").into()); + } + for (input, expected) in [ + ("/", SlashCommand::Statusline), + ("/sta", SlashCommand::Statusline), + ("/status", SlashCommand::Status), + ] { + assert_eq!(select(&mut chat, input), InputResult::Command(expected)); + } +} + #[tokio::test] async fn queued_slash_compact_dispatches_after_active_turn() { let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;