mirror of
https://github.com/openai/codex.git
synced 2026-05-30 07:50:17 +00:00
This updates TUI skill mentions to show a fallback label when a skill does not define a display name, so unnamed skills remain understandable in the picker without changing behavior for skills that already have one. <img width="1028" height="198" alt="Screenshot 2026-04-20 at 6 25 15 PM" src="https://github.com/user-attachments/assets/84077b85-99d0-4db9-b533-37e1887b4506" />
55 lines
1.5 KiB
Rust
55 lines
1.5 KiB
Rust
use codex_core_skills::model::SkillMetadata;
|
|
use codex_utils_fuzzy_match::fuzzy_match;
|
|
|
|
use crate::text_formatting::truncate_text;
|
|
|
|
pub(crate) const SKILL_NAME_TRUNCATE_LEN: usize = 21;
|
|
|
|
pub(crate) fn skill_display_name(skill: &SkillMetadata) -> String {
|
|
if let Some(display_name) = skill
|
|
.interface
|
|
.as_ref()
|
|
.and_then(|interface| interface.display_name.as_deref())
|
|
{
|
|
return display_name.to_string();
|
|
}
|
|
|
|
if let Some((plugin_name, skill_name)) = skill.name.split_once(':')
|
|
&& !plugin_name.is_empty()
|
|
&& !skill_name.is_empty()
|
|
{
|
|
return format!("{skill_name} ({plugin_name})");
|
|
}
|
|
|
|
skill.name.clone()
|
|
}
|
|
|
|
pub(crate) fn skill_description(skill: &SkillMetadata) -> &str {
|
|
skill
|
|
.interface
|
|
.as_ref()
|
|
.and_then(|interface| interface.short_description.as_deref())
|
|
.or(skill.short_description.as_deref())
|
|
.unwrap_or(&skill.description)
|
|
}
|
|
|
|
pub(crate) fn truncate_skill_name(name: &str) -> String {
|
|
truncate_text(name, SKILL_NAME_TRUNCATE_LEN)
|
|
}
|
|
|
|
pub(crate) fn match_skill(
|
|
filter: &str,
|
|
display_name: &str,
|
|
skill_name: &str,
|
|
) -> Option<(Option<Vec<usize>>, i32)> {
|
|
if let Some((indices, score)) = fuzzy_match(display_name, filter) {
|
|
return Some((Some(indices), score));
|
|
}
|
|
if display_name != skill_name
|
|
&& let Some((_indices, score)) = fuzzy_match(skill_name, filter)
|
|
{
|
|
return Some((None, score));
|
|
}
|
|
None
|
|
}
|