tui: dedupe alias-expanded popup commands

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Charles Cunningham
2026-03-15 23:36:05 -07:00
co-authored by Codex
parent d65960d57b
commit 1a54e52fd9
4 changed files with 63 additions and 19 deletions
+12 -10
View File
@@ -29,7 +29,7 @@ pub(crate) enum CommandItem {
pub(crate) struct CommandPopup {
command_filter: String,
builtins: Vec<(&'static str, SlashCommand)>,
builtins: Vec<SlashCommand>,
prompts: Vec<CustomPrompt>,
state: ScrollState,
}
@@ -62,13 +62,15 @@ impl From<CommandPopupFlags> for slash_commands::BuiltinCommandFlags {
impl CommandPopup {
pub(crate) fn new(mut prompts: Vec<CustomPrompt>, flags: CommandPopupFlags) -> Self {
// Keep built-in availability in sync with the composer.
let builtins: Vec<(&'static str, SlashCommand)> =
slash_commands::builtins_for_input(flags.into())
.into_iter()
.filter(|(name, _)| !name.starts_with("debug"))
.collect();
let builtins: Vec<SlashCommand> = slash_commands::visible_builtins_for_input(flags.into())
.into_iter()
.filter(|cmd| !cmd.command().starts_with("debug"))
.collect();
// Exclude prompts that collide with builtin command names and sort by name.
let exclude: HashSet<String> = builtins.iter().map(|(n, _)| (*n).to_string()).collect();
let exclude: HashSet<String> = builtins
.iter()
.map(|cmd| cmd.command().to_string())
.collect();
prompts.retain(|p| !exclude.contains(&p.name));
prompts.sort_by(|a, b| a.name.cmp(&b.name));
Self {
@@ -83,7 +85,7 @@ impl CommandPopup {
let exclude: HashSet<String> = self
.builtins
.iter()
.map(|(n, _)| (*n).to_string())
.map(|cmd| cmd.command().to_string())
.collect();
prompts.retain(|p| !exclude.contains(&p.name));
prompts.sort_by(|a, b| a.name.cmp(&b.name));
@@ -142,7 +144,7 @@ impl CommandPopup {
let mut out: Vec<(CommandItem, Option<Vec<usize>>)> = Vec::new();
if filter.is_empty() {
// Built-ins first, in presentation order.
for (_, cmd) in self.builtins.iter() {
for cmd in self.builtins.iter() {
if ALIAS_COMMANDS.contains(cmd) {
continue;
}
@@ -183,7 +185,7 @@ impl CommandPopup {
}
};
for (_, cmd) in self.builtins.iter() {
for cmd in self.builtins.iter() {
push_match(CommandItem::Builtin(*cmd), cmd.command(), None, 0);
}
// Support both search styles:
@@ -9,6 +9,7 @@ use codex_utils_fuzzy_match::fuzzy_match;
use crate::slash_command::SlashCommand;
use crate::slash_command::built_in_slash_commands;
use crate::slash_command::visible_built_in_slash_commands;
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct BuiltinCommandFlags {
@@ -38,6 +39,23 @@ pub(crate) fn builtins_for_input(flags: BuiltinCommandFlags) -> Vec<(&'static st
.collect()
}
/// Return the visible built-ins once each, in popup presentation order.
pub(crate) fn visible_builtins_for_input(flags: BuiltinCommandFlags) -> Vec<SlashCommand> {
visible_built_in_slash_commands()
.into_iter()
.filter(|cmd| flags.allow_elevate_sandbox || *cmd != SlashCommand::ElevateSandbox)
.filter(|cmd| {
flags.collaboration_modes_enabled
|| !matches!(*cmd, SlashCommand::Collab | SlashCommand::Plan)
})
.filter(|cmd| flags.connectors_enabled || *cmd != SlashCommand::Apps)
.filter(|cmd| flags.fast_command_enabled || *cmd != SlashCommand::Fast)
.filter(|cmd| flags.personality_command_enabled || *cmd != SlashCommand::Personality)
.filter(|cmd| flags.realtime_conversation_enabled || *cmd != SlashCommand::Realtime)
.filter(|cmd| flags.audio_device_selection_enabled || *cmd != SlashCommand::Settings)
.collect()
}
/// Find a single built-in command by exact name, after applying the gating rules.
pub(crate) fn find_builtin_command(name: &str, flags: BuiltinCommandFlags) -> Option<SlashCommand> {
let cmd = SlashCommand::from_str(name).ok()?;
@@ -114,6 +132,16 @@ mod tests {
assert_eq!(SlashCommand::MultiAgents.command(), "subagents");
}
#[test]
fn visible_builtins_keep_multi_agents_deduplicated() {
let builtins = visible_builtins_for_input(all_enabled_flags());
let multi_agents: Vec<_> = builtins
.into_iter()
.filter(|cmd| *cmd == SlashCommand::MultiAgents)
.collect();
assert_eq!(multi_agents, vec![SlashCommand::MultiAgents]);
}
#[test]
fn fast_command_is_hidden_when_disabled() {
let mut flags = all_enabled_flags();
+8 -4
View File
@@ -4962,6 +4962,7 @@ impl ChatWidget {
.send(AppEvent::CodexOp(Op::OverrideTurnContext {
cwd: None,
approval_policy: Some(preset.approval),
approvals_reviewer: Some(ApprovalsReviewer::User),
sandbox_policy: Some(sandbox.clone()),
windows_sandbox_level: None,
model: None,
@@ -4975,6 +4976,8 @@ impl ChatWidget {
.send(AppEvent::UpdateAskForApprovalPolicy(preset.approval));
self.app_event_tx
.send(AppEvent::UpdateSandboxPolicy(sandbox));
self.app_event_tx
.send(AppEvent::UpdateApprovalsReviewer(ApprovalsReviewer::User));
self.app_event_tx.send(AppEvent::InsertHistoryCell(Box::new(
history_cell::new_info_event(format!("Permissions updated to {label}"), None),
)));
@@ -5250,6 +5253,7 @@ impl ChatWidget {
.send(AppEvent::CodexOp(Op::OverrideTurnContext {
cwd: None,
approval_policy: None,
approvals_reviewer: None,
sandbox_policy: None,
model: None,
effort: None,
@@ -8486,6 +8490,7 @@ impl ChatWidget {
});
if guardian_approval_enabled {
let guardian_preset = preset.clone();
items.push(SelectionItem {
name: "Guardian Approvals".to_string(),
description: Some(
@@ -8498,11 +8503,10 @@ impl ChatWidget {
current_sandbox,
&preset,
),
actions: Self::approval_preset_actions(
preset.approval,
preset.sandbox.clone(),
"Guardian Approvals".to_string(),
actions: Self::approval_preset_actions_for_reviewer(
guardian_preset.id,
ApprovalsReviewer::GuardianSubagent,
&[],
),
dismiss_on_select: true,
disabled_reason: approval_disabled_reason
+15 -5
View File
@@ -5427,6 +5427,7 @@ async fn queued_init_replay_stops_after_submitting_user_turn() {
model_provider_id: "test-provider".to_string(),
service_tier: None,
approval_policy: AskForApproval::Never,
approvals_reviewer: ApprovalsReviewer::User,
sandbox_policy: SandboxPolicy::new_read_only_policy(),
cwd: tempdir.path().to_path_buf(),
reasoning_effort: Some(ReasoningEffortConfig::default()),
@@ -5674,6 +5675,7 @@ async fn queued_plan_replay_stops_after_submitting_user_turn() {
model_provider_id: "test-provider".to_string(),
service_tier: None,
approval_policy: AskForApproval::Never,
approvals_reviewer: ApprovalsReviewer::User,
sandbox_policy: SandboxPolicy::new_read_only_policy(),
cwd: PathBuf::from("/home/user/project"),
reasoning_effort: Some(ReasoningEffortConfig::default()),
@@ -8577,6 +8579,7 @@ async fn queued_followup_waits_for_popup_opened_during_running_turn() {
model_provider_id: "test-provider".to_string(),
service_tier: None,
approval_policy: AskForApproval::Never,
approvals_reviewer: ApprovalsReviewer::User,
sandbox_policy: SandboxPolicy::new_read_only_policy(),
cwd: PathBuf::from("/home/user/project"),
reasoning_effort: Some(ReasoningEffortConfig::default()),
@@ -9454,6 +9457,7 @@ async fn permissions_selection_can_disable_guardian_approvals() {
}
chat.config.notices.hide_full_access_warning = Some(true);
chat.set_feature_enabled(Feature::GuardianApproval, true);
chat.config.approvals_reviewer = ApprovalsReviewer::GuardianSubagent;
chat.config
.permissions
.approval_policy
@@ -9471,11 +9475,14 @@ async fn permissions_selection_can_disable_guardian_approvals() {
let events = std::iter::from_fn(|| rx.try_recv().ok()).collect::<Vec<_>>();
assert!(
events.iter().any(|event| matches!(
event,
AppEvent::UpdateApprovalsReviewer(ApprovalsReviewer::User)
)),
"expected selecting Default from Guardian Approvals to switch back to manual approval review: {events:?}"
events.iter().any(|event| {
matches!(
event,
AppEvent::HandleSlashCommandDraft(draft)
if *draft == ChatWidget::approval_preset_draft("auto", &[])
)
}),
"expected selecting Default from Guardian Approvals to queue the default approvals draft: {events:?}"
);
assert!(
!events
@@ -12077,6 +12084,7 @@ async fn queued_theme_selection_resumes_followup_after_idle_resume() {
model_provider_id: "test-provider".to_string(),
service_tier: None,
approval_policy: AskForApproval::Never,
approvals_reviewer: ApprovalsReviewer::User,
sandbox_policy: SandboxPolicy::new_read_only_policy(),
cwd: PathBuf::from("/home/user/project"),
reasoning_effort: Some(ReasoningEffortConfig::default()),
@@ -12145,6 +12153,7 @@ async fn queued_personality_selection_resumes_followup_after_idle_resume() {
model_provider_id: "test-provider".to_string(),
service_tier: None,
approval_policy: AskForApproval::Never,
approvals_reviewer: ApprovalsReviewer::User,
sandbox_policy: SandboxPolicy::new_read_only_policy(),
cwd: PathBuf::from("/home/user/project"),
reasoning_effort: Some(ReasoningEffortConfig::default()),
@@ -12224,6 +12233,7 @@ async fn queued_followup_waits_for_popup_dismissal_before_idle_resume() {
model_provider_id: "test-provider".to_string(),
service_tier: None,
approval_policy: AskForApproval::Never,
approvals_reviewer: ApprovalsReviewer::User,
sandbox_policy: SandboxPolicy::new_read_only_policy(),
cwd: PathBuf::from("/home/user/project"),
reasoning_effort: Some(ReasoningEffortConfig::default()),