Match core skill ordering in extension catalogs (#34746)

## Why

Core-compatible catalog rendering needs to preserve the core renderer's skill
priority, including when metadata budgets omit lower-priority entries.

## What changed

- Carry each host skill's `SkillScope` into its catalog entry.
- Under `CoreCompatible`, order visible skills by system, admin, repo, and user
  scope, then by name and prompt resource ID.
- Preserve insertion order under `ExtensionCompatible`.

## Testing

Add coverage for propagating host skill scope and for both rendering policies.

GitOrigin-RevId: 9594a177edb2166abf1b5719c51a46fcee000600
This commit is contained in:
felixxia-oai authored and copyberry committed 2026-07-22 12:40:16 +00:00
1 parent f21f98936c
commit 2ffe8cd579
5 files changed
+197 -4

No files matched your search

+27 -1
View File
@@ -1,5 +1,6 @@
use std::borrow::Cow;
use codex_protocol::protocol::SkillScope;
use codex_utils_string::approx_token_count;
use codex_utils_string::take_bytes_at_char_boundary;
@@ -41,6 +42,27 @@ impl SkillCatalogRenderPolicy {
.unwrap_or(entry.description.as_str()),
}
}
fn order_entries(self, entries: &mut [&SkillCatalogEntry]) {
match self {
Self::CoreCompatible => {
let scope_rank = |entry: &SkillCatalogEntry| match entry.prompt_scope() {
Some(SkillScope::System) => 0,
Some(SkillScope::Admin) => 1,
Some(SkillScope::Repo) => 2,
Some(SkillScope::User) => 3,
None => 4,
};
entries.sort_by(|a, b| {
scope_rank(a)
.cmp(&scope_rank(b))
.then_with(|| a.name.cmp(&b.name))
.then_with(|| a.main_prompt.as_str().cmp(b.main_prompt.as_str()))
});
}
Self::ExtensionCompatible => {}
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -287,10 +309,14 @@ pub(crate) fn available_skills_fragment(
policy: SkillCatalogRenderPolicy,
budget: SkillMetadataBudget,
) -> Option<AvailableSkillsInstructions> {
let skill_lines = catalog
let mut entries = catalog
.entries
.iter()
.filter(|entry| entry.enabled && entry.prompt_visible)
.collect::<Vec<_>>();
policy.order_entries(&mut entries);
let skill_lines = entries
.iter()
.map(|entry| SkillLine::new(entry, policy))
.collect();
let (mut skill_lines, mut omitted) = render_skill_lines(skill_lines, budget);