Remove Codex skill mention plumbing

This commit is contained in:
Meta Vens 2026-05-14 01:55:09 +01:00
commit 42df76747b
47 changed files with 108 additions and 1963 deletions

View file

@ -121,7 +121,7 @@ impl ChatWidget {
match item {
UserInput::Text { text, .. } => message.push_str(text),
UserInput::Image { .. } | UserInput::LocalImage { .. } => image_count += 1,
UserInput::Skill { .. } | UserInput::Mention { .. } => {}
UserInput::Mention { .. } => {}
_ => {}
}
}
@ -165,7 +165,7 @@ impl ChatWidget {
),
UserInput::Image { image_url } => remote_image_urls.push(image_url.clone()),
UserInput::LocalImage { path } => local_images.push(path.clone()),
UserInput::Skill { .. } | UserInput::Mention { .. } => {}
UserInput::Mention { .. } => {}
_ => {}
}
}

View file

@ -1,252 +0,0 @@
use std::collections::HashMap;
use std::collections::HashSet;
use super::ChatWidget;
use codex_core_skills::model::SkillMetadata;
use codex_protocol::parse_command::ParsedCommand;
const TOOL_MENTION_SIGIL: char = '$';
impl ChatWidget {
pub(crate) fn annotate_skill_reads_in_parsed_cmd(
&self,
mut parsed_cmd: Vec<ParsedCommand>,
) -> Vec<ParsedCommand> {
if self.skills_all.is_empty() {
return parsed_cmd;
}
for parsed in &mut parsed_cmd {
let ParsedCommand::Read { name, path, .. } = parsed else {
continue;
};
if name != "SKILL.md" {
continue;
}
// Best effort only: annotate exact SKILL.md path matches from the loaded skills list.
if let Some(skill) = self
.skills_all
.iter()
.find(|skill| skill.path.as_path() == path)
{
*name = format!("{name} ({} skill)", skill.name);
}
}
parsed_cmd
}
}
pub(crate) fn collect_tool_mentions(
text: &str,
mention_paths: &HashMap<String, String>,
) -> ToolMentions {
let mut mentions = extract_tool_mentions_from_text(text);
for (name, path) in mention_paths {
if mentions.names.contains(name) {
mentions.linked_paths.insert(name.clone(), path.clone());
}
}
mentions
}
pub(crate) fn find_skill_mentions_with_tool_mentions(
mentions: &ToolMentions,
skills: &[SkillMetadata],
) -> Vec<SkillMetadata> {
let mention_skill_paths: HashSet<&str> = mentions
.linked_paths
.values()
.filter(|path| is_skill_path(path))
.map(|path| normalize_skill_path(path))
.collect();
let mut seen_names = HashSet::new();
let mut seen_paths = HashSet::new();
let mut matches: Vec<SkillMetadata> = Vec::new();
for skill in skills {
if seen_paths.contains(&skill.path_to_skills_md) {
continue;
}
let path_str = skill.path_to_skills_md.to_string_lossy();
if mention_skill_paths.contains(path_str.as_ref()) {
seen_paths.insert(skill.path_to_skills_md.clone());
seen_names.insert(skill.name.clone());
matches.push(skill.clone());
}
}
for skill in skills {
if seen_paths.contains(&skill.path_to_skills_md) {
continue;
}
if mentions.names.contains(&skill.name) && seen_names.insert(skill.name.clone()) {
seen_paths.insert(skill.path_to_skills_md.clone());
matches.push(skill.clone());
}
}
matches
}
pub(crate) struct ToolMentions {
names: HashSet<String>,
linked_paths: HashMap<String, String>,
}
fn extract_tool_mentions_from_text(text: &str) -> ToolMentions {
extract_tool_mentions_from_text_with_sigil(text, TOOL_MENTION_SIGIL)
}
fn extract_tool_mentions_from_text_with_sigil(text: &str, sigil: char) -> ToolMentions {
let text_bytes = text.as_bytes();
let mut names: HashSet<String> = HashSet::new();
let mut linked_paths: HashMap<String, String> = HashMap::new();
let mut index = 0;
while index < text_bytes.len() {
let byte = text_bytes[index];
if byte == b'['
&& let Some((name, path, end_index)) =
parse_linked_tool_mention(text, text_bytes, index, sigil)
{
if !is_common_env_var(name) {
if is_skill_path(path) {
names.insert(name.to_string());
}
linked_paths
.entry(name.to_string())
.or_insert(path.to_string());
}
index = end_index;
continue;
}
if byte != sigil as u8 {
index += 1;
continue;
}
let name_start = index + 1;
let Some(first_name_byte) = text_bytes.get(name_start) else {
index += 1;
continue;
};
if !is_mention_name_char(*first_name_byte) {
index += 1;
continue;
}
let mut name_end = name_start + 1;
while let Some(next_byte) = text_bytes.get(name_end)
&& is_mention_name_char(*next_byte)
{
name_end += 1;
}
let name = &text[name_start..name_end];
if !is_common_env_var(name) {
names.insert(name.to_string());
}
index = name_end;
}
ToolMentions {
names,
linked_paths,
}
}
fn parse_linked_tool_mention<'a>(
text: &'a str,
text_bytes: &[u8],
start: usize,
sigil: char,
) -> Option<(&'a str, &'a str, usize)> {
let sigil_index = start + 1;
if text_bytes.get(sigil_index) != Some(&(sigil as u8)) {
return None;
}
let name_start = sigil_index + 1;
let first_name_byte = text_bytes.get(name_start)?;
if !is_mention_name_char(*first_name_byte) {
return None;
}
let mut name_end = name_start + 1;
while let Some(next_byte) = text_bytes.get(name_end)
&& is_mention_name_char(*next_byte)
{
name_end += 1;
}
if text_bytes.get(name_end) != Some(&b']') {
return None;
}
let mut path_start = name_end + 1;
while let Some(next_byte) = text_bytes.get(path_start)
&& next_byte.is_ascii_whitespace()
{
path_start += 1;
}
if text_bytes.get(path_start) != Some(&b'(') {
return None;
}
let mut path_end = path_start + 1;
while let Some(next_byte) = text_bytes.get(path_end)
&& *next_byte != b')'
{
path_end += 1;
}
if text_bytes.get(path_end) != Some(&b')') {
return None;
}
let path = text[path_start + 1..path_end].trim();
if path.is_empty() {
return None;
}
let name = &text[name_start..name_end];
Some((name, path, path_end + 1))
}
fn is_common_env_var(name: &str) -> bool {
let upper = name.to_ascii_uppercase();
matches!(
upper.as_str(),
"PATH"
| "HOME"
| "USER"
| "SHELL"
| "PWD"
| "TMPDIR"
| "TEMP"
| "TMP"
| "LANG"
| "TERM"
| "XDG_CONFIG_HOME"
)
}
fn is_mention_name_char(byte: u8) -> bool {
matches!(byte, b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9' | b'_' | b'-')
}
fn is_skill_path(path: &str) -> bool {
path.starts_with("skill://")
|| (!path.contains("://")
&& path
.rsplit(['/', '\\'])
.next()
.is_some_and(|name| name.eq_ignore_ascii_case("SKILL.md")))
}
fn normalize_skill_path(path: &str) -> &str {
path.strip_prefix("skill://").unwrap_or(path)
}

View file

@ -91,7 +91,6 @@ pub(super) use codex_config::types::ApprovalsReviewer;
pub(super) use codex_config::types::Notifications;
#[cfg(target_os = "windows")]
pub(super) use codex_config::types::WindowsSandboxModeToml;
pub(super) use codex_core_skills::model::SkillMetadata;
pub(super) use codex_features::FEATURES;
pub(super) use codex_features::Feature;
pub(super) use codex_git_utils::CommitLogEntry;
@ -172,7 +171,6 @@ pub(super) use codex_protocol::protocol::ReviewRequest;
pub(super) use codex_protocol::protocol::ReviewTarget;
pub(super) use codex_protocol::protocol::SessionConfiguredEvent;
pub(super) use codex_protocol::protocol::SessionSource;
pub(super) use codex_protocol::protocol::SkillScope;
pub(super) use codex_protocol::protocol::StreamErrorEvent;
pub(super) use codex_protocol::protocol::TerminalInteractionEvent;
pub(super) use codex_protocol::protocol::ThreadRolledBackEvent;

View file

@ -368,86 +368,6 @@ async fn enter_with_only_remote_images_does_not_submit_when_input_disabled() {
assert_no_submit_op(&mut op_rx);
}
#[tokio::test]
async fn submission_prefers_selected_duplicate_skill_path() {
let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
let conversation_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = codex_protocol::protocol::SessionConfiguredEvent {
session_id: conversation_id,
forked_from_id: None,
thread_name: None,
model: "test-model".to_string(),
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: test_path_buf("/home/user/project").abs(),
reasoning_effort: Some(ReasoningEffortConfig::default()),
history_log_id: 0,
history_entry_count: 0,
initial_messages: None,
network_proxy: None,
rollout_path: Some(rollout_file.path().to_path_buf()),
};
chat.handle_codex_event(Event {
id: "initial".into(),
msg: EventMsg::SessionConfigured(configured),
});
drain_insert_history(&mut rx);
let repo_skill_path = test_path_buf("/tmp/repo/figma/SKILL.md").abs();
let user_skill_path = test_path_buf("/tmp/user/figma/SKILL.md").abs();
chat.set_skills(Some(vec![
SkillMetadata {
name: "figma".to_string(),
description: "Repo skill".to_string(),
short_description: None,
interface: None,
dependencies: None,
policy: None,
path_to_skills_md: repo_skill_path,
scope: SkillScope::Repo,
},
SkillMetadata {
name: "figma".to_string(),
description: "User skill".to_string(),
short_description: None,
interface: None,
dependencies: None,
policy: None,
path_to_skills_md: user_skill_path.clone(),
scope: SkillScope::User,
},
]));
chat.bottom_pane.set_composer_text_with_mention_bindings(
"please use $figma now".to_string(),
Vec::new(),
Vec::new(),
vec![MentionBinding {
mention: "figma".to_string(),
path: user_skill_path.to_string_lossy().into_owned(),
}],
);
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
let items = match next_submit_op(&mut op_rx) {
Op::UserTurn { items, .. } => items,
other => panic!("expected Op::UserTurn, got {other:?}"),
};
let selected_skill_paths = items
.iter()
.filter_map(|item| match item {
UserInput::Skill { path, .. } => Some(path.clone()),
_ => None,
})
.collect::<Vec<_>>();
assert_eq!(selected_skill_paths, vec![user_skill_path.to_path_buf()]);
}
#[tokio::test]
async fn blocked_image_restore_preserves_mention_bindings() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
@ -464,7 +384,7 @@ async fn blocked_image_restore_preserves_mention_bindings() {
}];
let mention_bindings = vec![MentionBinding {
mention: "file".to_string(),
path: "/tmp/skills/file/SKILL.md".to_string(),
path: "mcp://file".to_string(),
}];
chat.restore_blocked_image_submission(
@ -998,10 +918,6 @@ fn rendered_user_message_event_from_inputs_matches_flattened_user_message_shape(
UserInput::LocalImage {
path: local_image.clone(),
},
UserInput::Skill {
name: "demo".to_string(),
path: PathBuf::from("/tmp/skill/SKILL.md"),
},
UserInput::Mention {
name: "repo".to_string(),
path: "mcp://repo".to_string(),

View file

@ -166,7 +166,6 @@ pub(super) async fn make_chatwidget_manual(
placeholder_text: "Ask Codex to do anything".to_string(),
disable_paste_burst: false,
animations_enabled: cfg.animations,
skills: None,
});
bottom.set_collaboration_modes_enabled(/*enabled*/ true);
let model_catalog = test_model_catalog(&cfg);
@ -221,7 +220,6 @@ pub(super) async fn make_chatwidget_manual(
collab_agent_metadata: HashMap::new(),
pending_collab_spawn_requests: HashMap::new(),
suppressed_exec_calls: HashSet::new(),
skills_all: Vec::new(),
last_unified_wait: None,
unified_exec_wait_streak: None,
turn_sleep_inhibitor: SleepInhibitor::new(prevent_idle_sleep),

View file

@ -1080,7 +1080,7 @@ async fn submit_user_message_ignores_plugin_mentions_from_bindings() {
text_elements: Vec::new(),
mention_bindings: vec![MentionBinding {
mention: "sample".to_string(),
path: "skill://sample".to_string(),
path: "mcp://sample".to_string(),
}],
});

View file

@ -911,7 +911,7 @@ async fn manual_interrupt_restores_pending_steer_mention_bindings_to_composer()
let mention_bindings = vec![MentionBinding {
mention: "figma".to_string(),
path: "/tmp/skills/figma/SKILL.md".to_string(),
path: "mcp://figma".to_string(),
}];
chat.bottom_pane.set_composer_text_with_mention_bindings(
"please use $figma".to_string(),