Move explicit skill invocation into SkillsExtension

This commit is contained in:
jif-oai
2026-06-18 11:48:21 +02:00
parent 7d97a6f571
commit b991d3854d
26 changed files with 846 additions and 599 deletions
@@ -1,3 +1,4 @@
use std::collections::HashSet;
use std::path::PathBuf;
use codex_protocol::ThreadId;
@@ -21,8 +22,15 @@ pub struct TurnInputContext {
pub thread_id: ThreadId,
/// Stable host-owned turn identifier.
pub turn_id: String,
/// Model slug selected for this turn.
pub model: String,
/// User input submitted for this turn.
pub user_input: Vec<UserInput>,
/// Plain tool names already claimed by host-managed capabilities.
///
/// Contributors should not resolve these names through ambiguous plaintext
/// mentions. Explicit resource or path mentions remain valid.
pub reserved_plain_tool_names: HashSet<String>,
/// Resolved turn environments, in host priority order.
pub environments: Vec<TurnInputEnvironment>,
}
+2
View File
@@ -14,6 +14,8 @@ doctest = false
workspace = true
[dependencies]
codex-analytics = { workspace = true }
codex-connectors = { workspace = true }
codex-core-skills = { workspace = true }
codex-exec-server = { workspace = true }
codex-extension-api = { workspace = true }
+114 -28
View File
@@ -1,7 +1,17 @@
use std::collections::HashSet;
use std::sync::Arc;
use codex_analytics::AnalyticsEventsClient;
use codex_analytics::InvocationType;
use codex_analytics::SkillInvocation;
use codex_analytics::build_track_events_context;
use codex_connectors::ExplicitConnectorMentions;
use codex_core_skills::HostSkillsSnapshot;
use codex_core_skills::injection::InjectedHostSkillPrompts;
use codex_core_skills::SkillMetadata;
use codex_core_skills::injection::ToolMentionKind;
use codex_core_skills::injection::app_id_from_path;
use codex_core_skills::injection::extract_tool_mentions;
use codex_core_skills::injection::tool_kind_for_path;
use codex_exec_server::LOCAL_ENVIRONMENT_ID;
use codex_extension_api::ConfigContributor;
use codex_extension_api::ContextContributionContext;
@@ -20,6 +30,8 @@ use codex_extension_api::ToolExecutor;
use codex_extension_api::TurnInputContext;
use codex_extension_api::TurnInputContributor;
use codex_mcp::McpResourceClient;
use codex_mcp::McpServerDependencies;
use codex_mcp::McpServerDependency;
use codex_otel::SessionTelemetry;
use codex_protocol::capabilities::SelectedCapabilityRoot;
use codex_protocol::protocol::Event;
@@ -112,6 +124,7 @@ where
Box::pin(async move {
let session_store = context.session_store;
let thread_store = context.thread_store;
let turn_store = context.turn_store;
let Some(thread_state) = thread_store.get::<SkillsThreadState>() else {
return Vec::new();
};
@@ -119,11 +132,11 @@ where
if !config.include_instructions {
return Vec::new();
}
let host_snapshot = context.turn_store.get::<HostSkillsSnapshot>();
let host_snapshot = turn_store.get::<HostSkillsSnapshot>();
let catalog = self
.list_skills(
SkillListQuery {
turn_id: context.turn_store.level_id().to_string(),
turn_id: turn_store.level_id().to_string(),
executor_roots: thread_state.selected_roots().to_vec(),
host_snapshot: host_snapshot.clone(),
include_host_skills: true,
@@ -206,7 +219,7 @@ where
turn_id: input.turn_id.clone(),
executor_roots: thread_state.selected_roots().to_vec(),
host_snapshot: host_snapshot.clone(),
include_host_skills: false,
include_host_skills: true,
include_bundled_skills: config.bundled_skills_enabled,
include_orchestrator_skills: thread_state.orchestrator_skills_enabled(),
mcp_resources: session_store.get::<McpResourceClient>(),
@@ -216,11 +229,43 @@ where
self.emit_warning(input.thread_id, &input.turn_id, warning.clone());
}
let selected_entries = collect_explicit_skill_mentions(&input.user_input, &catalog);
let selected_entries = collect_explicit_skill_mentions(
&input.user_input,
&catalog,
&input.reserved_plain_tool_names,
);
let mut fragments: Vec<Box<dyn ContextualUserFragment + Send>> = Vec::new();
let skill_names = catalog
.entries
.iter()
.filter(|entry| entry.enabled)
.map(|entry| entry.name.to_ascii_lowercase())
.collect::<HashSet<_>>();
let mut mcp_dependencies = McpServerDependencies::default();
for entry in &selected_entries {
for dependency in entry
.dependencies
.iter()
.flat_map(|dependencies| &dependencies.tools)
.filter(|dependency| dependency.r#type.eq_ignore_ascii_case("mcp"))
{
mcp_dependencies.push(McpServerDependency {
source_name: entry.name.clone(),
name: dependency.value.clone(),
transport: dependency.transport.clone(),
command: dependency.command.clone(),
url: dependency.url.clone(),
});
}
}
if !mcp_dependencies.is_empty() {
turn_store.insert(mcp_dependencies);
}
let mut warnings = catalog.warnings.clone();
let mut main_prompts_injected = false;
let mut injected_host_skill_prompts = InjectedHostSkillPrompts::default();
let mut connector_mentions = ExplicitConnectorMentions::default();
let mut skill_invocations = Vec::new();
for entry in &selected_entries {
match self
.read_main_prompt(entry, host_snapshot.clone(), session_store, &thread_state)
@@ -229,6 +274,35 @@ where
Ok(read_result) => {
let (contents, truncated) =
truncate_main_prompt_contents(read_result.contents.as_str());
let tool_mentions = extract_tool_mentions(&contents);
for path in tool_mentions.paths() {
if tool_kind_for_path(path) == ToolMentionKind::App
&& let Some(connector_id) = app_id_from_path(path)
{
connector_mentions.insert_connector_id(connector_id);
}
}
for name in tool_mentions.plain_names() {
if !skill_names.contains(&name.to_ascii_lowercase()) {
connector_mentions.insert_plain_name(name);
}
}
if let Some(skill) = host_skill_for_entry(host_snapshot.as_deref(), entry) {
if let Some(telemetry) = turn_store.get::<SessionTelemetry>() {
telemetry.counter(
"codex.skill.injected",
/*inc*/ 1,
&[("status", "ok"), ("skill", skill.name.as_str())],
);
}
skill_invocations.push(SkillInvocation {
skill_name: skill.name.clone(),
skill_scope: skill.scope,
skill_path: skill.path_to_skills_md.to_path_buf(),
plugin_id: skill.plugin_id.clone(),
invocation_type: InvocationType::Explicit,
});
}
if truncated {
let warning = format!(
"Skill `{}` exceeded the main prompt context limit and was truncated.",
@@ -248,33 +322,35 @@ where
};
fragments.push(Box::new(fragment));
main_prompts_injected = true;
if entry.authority.kind == SkillSourceKind::Host {
injected_host_skill_prompts.insert_path(entry.main_prompt.as_str());
}
}
Err(message) => {
if let Some(skill) = host_skill_for_entry(host_snapshot.as_deref(), entry)
&& let Some(telemetry) = turn_store.get::<SessionTelemetry>()
{
telemetry.counter(
"codex.skill.injected",
/*inc*/ 1,
&[("status", "error"), ("skill", skill.name.as_str())],
);
}
let warning = format!("Failed to load skill `{}`: {message}", entry.name);
self.emit_warning(input.thread_id, &input.turn_id, warning.clone());
warnings.push(warning);
}
}
}
if let Some(host_snapshot) = &host_snapshot {
for entry in selected_entries
.iter()
.filter(|entry| entry.authority.kind != SkillSourceKind::Host)
{
for host_skill in host_snapshot
.outcome()
.skills
.iter()
.filter(|host_skill| host_skill.name == entry.name)
{
injected_host_skill_prompts
.insert_path(host_skill.path_to_skills_md.to_string_lossy());
}
}
if !connector_mentions.is_empty() {
turn_store.insert(connector_mentions);
}
if let Some(analytics) = session_store.get::<AnalyticsEventsClient>() {
analytics.track_skill_invocations(
build_track_events_context(
input.model,
thread_store.level_id().to_string(),
input.turn_id,
),
skill_invocations,
);
}
turn_store.insert(SkillsTurnState {
@@ -283,9 +359,6 @@ where
warnings,
main_prompts_injected,
});
if !injected_host_skill_prompts.is_empty() {
turn_store.insert(injected_host_skill_prompts);
}
fragments
})
@@ -350,6 +423,19 @@ impl<C> SkillsExtension<C> {
}
}
fn host_skill_for_entry<'a>(
host_snapshot: Option<&'a HostSkillsSnapshot>,
entry: &SkillCatalogEntry,
) -> Option<&'a SkillMetadata> {
if entry.authority.kind != SkillSourceKind::Host {
return None;
}
host_snapshot?.outcome().skills.iter().find(|skill| {
let path = skill.path_to_skills_md.to_string_lossy();
path == entry.main_prompt.as_str() || path.replace('\\', "/") == entry.main_prompt.as_str()
})
}
pub fn install<C>(
registry: &mut ExtensionRegistryBuilder<C>,
config_from_host: impl Fn(&C) -> SkillsExtensionConfig + Send + Sync + 'static,
+20 -2
View File
@@ -7,12 +7,14 @@ use crate::catalog::SkillAuthority;
use crate::catalog::SkillCatalog;
use crate::catalog::SkillCatalogEntry;
use crate::catalog::SkillPackageId;
use crate::catalog::SkillSourceKind;
const SKILL_PATH_PREFIX: &str = "skill://";
pub(crate) fn collect_explicit_skill_mentions(
inputs: &[UserInput],
catalog: &SkillCatalog,
reserved_plain_tool_names: &HashSet<String>,
) -> Vec<SkillCatalogEntry> {
let mut selected = Vec::new();
let mut seen = HashSet::new();
@@ -54,13 +56,29 @@ pub(crate) fn collect_explicit_skill_mentions(
if blocked_plain_names.contains(name) {
continue;
}
if let Some(entry) = catalog
let matching_entries = catalog
.entries
.iter()
.find(|entry| entry.enabled && entry.name == name)
.filter(|entry| entry.enabled && entry.name == name);
if let Some(entry) = matching_entries
.clone()
.find(|entry| entry.authority.kind != SkillSourceKind::Host)
{
push_selected(entry, &mut seen, &mut selected);
continue;
}
let mut host_entries =
matching_entries.filter(|entry| entry.authority.kind == SkillSourceKind::Host);
let Some(entry) = host_entries.next() else {
continue;
};
if host_entries.next().is_some()
|| reserved_plain_tool_names.contains(&name.to_ascii_lowercase())
{
continue;
}
push_selected(entry, &mut seen, &mut selected);
}
}
+290 -15
View File
@@ -1,20 +1,25 @@
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::Mutex;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use codex_connectors::ExplicitConnectorMentions;
use codex_core_skills::HostSkillsSnapshot;
use codex_core_skills::SKILLS_HOW_TO_USE_WITH_ABSOLUTE_PATHS;
use codex_core_skills::SKILLS_INTRO_WITH_ABSOLUTE_PATHS;
use codex_core_skills::SkillLoadOutcome;
use codex_core_skills::SkillMetadata;
use codex_core_skills::model::SkillDependencies;
use codex_core_skills::model::SkillToolDependency;
use codex_extension_api::ContextContributionContext;
use codex_extension_api::ExtensionData;
use codex_extension_api::ExtensionEventSink;
use codex_extension_api::ExtensionRegistryBuilder;
use codex_extension_api::ThreadStartInput;
use codex_extension_api::TurnInputContext;
use codex_mcp::McpServerDependencies;
use codex_protocol::ThreadId;
use codex_protocol::capabilities::CapabilityRootLocation;
use codex_protocol::capabilities::SelectedCapabilityRoot;
@@ -52,9 +57,10 @@ type TestResult = Result<(), Box<dyn std::error::Error>>;
static NEXT_CODEX_HOME_ID: AtomicUsize = AtomicUsize::new(0);
const DEMO_SKILL_CONTENTS: &str =
"---\nname: demo\ndescription: Demo skill.\n---\n# Demo\n\nUse [$calendar](app://calendar).\n";
const STATIC_SKILL_CONTENTS: &str = "# Lint Fix\n\nRun the formatter.";
#[tokio::test]
async fn installed_extension_catalog_uses_host_service_snapshot() -> TestResult {
async fn installed_extension_uses_host_service_snapshot() -> TestResult {
let codex_home = test_codex_home();
let skill_path = codex_home.join("skills").join("demo").join("SKILL.md");
std::fs::create_dir_all(
@@ -90,7 +96,16 @@ async fn installed_extension_catalog_uses_host_service_snapshot() -> TestResult
description: "Demo skill.".to_string(),
short_description: None,
interface: None,
dependencies: None,
dependencies: Some(SkillDependencies {
tools: vec![SkillToolDependency {
r#type: "mcp".to_string(),
value: "docs".to_string(),
description: None,
transport: Some("streamable_http".to_string()),
command: None,
url: Some("https://example.com/mcp".to_string()),
}],
}),
policy: None,
path_to_skills_md: skill_path,
scope: SkillScope::User,
@@ -105,11 +120,57 @@ async fn installed_extension_catalog_uses_host_service_snapshot() -> TestResult
.contribute(prompt_context(&session_store, &thread_store, &turn_store))
.await;
let fragments = registry.turn_input_contributors()[0]
.contribute(
TurnInputContext {
thread_id: ThreadId::default(),
turn_id: "turn-1".to_string(),
model: "test-model".to_string(),
user_input: vec![UserInput::Text {
text: "$demo".to_string(),
text_elements: Vec::new(),
}],
reserved_plain_tool_names: Default::default(),
environments: Vec::new(),
},
&session_store,
&thread_store,
&turn_store,
)
.await;
let expected_catalog = format!(
"{SKILLS_INSTRUCTIONS_OPEN_TAG}\n## Skills\n{SKILLS_INTRO_WITH_ABSOLUTE_PATHS}\n### Available skills\n- demo: Demo skill. (file: {skill_prompt_path})\n### How to use skills\n{SKILLS_HOW_TO_USE_WITH_ABSOLUTE_PATHS}\n{SKILLS_INSTRUCTIONS_CLOSE_TAG}"
);
let expected_skill = format!(
"<skill>\n<name>demo</name>\n<path>{skill_prompt_path}</path>\n{DEMO_SKILL_CONTENTS}\n</skill>"
);
assert_eq!(1, prompt_fragments.len());
assert_eq!(expected_catalog, prompt_fragments[0].text());
assert_eq!(
vec![("user", expected_skill)],
fragments
.iter()
.map(|fragment| (fragment.role(), fragment.render()))
.collect::<Vec<_>>()
);
assert_eq!(
turn_store
.get::<ExplicitConnectorMentions>()
.ok_or("expected connector mentions")?
.resolve(&[]),
["calendar".to_string()].into_iter().collect()
);
assert_eq!(
turn_store
.get::<McpServerDependencies>()
.ok_or("expected MCP dependencies")?
.missing_from(&HashMap::new())
.keys()
.cloned()
.collect::<Vec<_>>(),
vec!["docs".to_string()]
);
std::fs::remove_dir_all(codex_home)?;
Ok(())
@@ -139,6 +200,7 @@ async fn selected_executor_catalog_is_context_and_selected_entrypoint_is_turn_in
entries: executor_entries,
warnings: Vec::new(),
},
contents: STATIC_SKILL_CONTENTS.to_string(),
read_requests: Arc::clone(&read_requests),
list_calls: None,
fail_first_list: false,
@@ -154,6 +216,7 @@ async fn selected_executor_catalog_is_context_and_selected_entrypoint_is_turn_in
)],
warnings: Vec::new(),
},
contents: STATIC_SKILL_CONTENTS.to_string(),
read_requests: Arc::new(Mutex::new(Vec::new())),
list_calls: None,
fail_first_list: false,
@@ -237,10 +300,12 @@ async fn selected_executor_catalog_is_context_and_selected_entrypoint_is_turn_in
TurnInputContext {
thread_id: ThreadId::default(),
turn_id: "turn-1".to_string(),
model: "test-model".to_string(),
user_input: vec![UserInput::Text {
text: "$lint-fix please".to_string(),
text_elements: Vec::new(),
}],
reserved_plain_tool_names: Default::default(),
environments: Vec::new(),
},
&session_store,
@@ -273,10 +338,12 @@ async fn selected_executor_catalog_is_context_and_selected_entrypoint_is_turn_in
TurnInputContext {
thread_id: ThreadId::default(),
turn_id: "turn-2".to_string(),
model: "test-model".to_string(),
user_input: vec![UserInput::Text {
text: "no skill this time".to_string(),
text_elements: Vec::new(),
}],
reserved_plain_tool_names: Default::default(),
environments: Vec::new(),
},
&session_store,
@@ -304,6 +371,7 @@ async fn orchestrator_catalog_snapshot_caches_failure() -> TestResult {
)],
warnings: Vec::new(),
},
contents: STATIC_SKILL_CONTENTS.to_string(),
read_requests: Arc::new(Mutex::new(Vec::new())),
list_calls: Some(Arc::clone(&list_calls)),
fail_first_list: true,
@@ -350,10 +418,12 @@ async fn orchestrator_catalog_snapshot_caches_failure() -> TestResult {
TurnInputContext {
thread_id: ThreadId::default(),
turn_id: turn_id.to_string(),
model: "test-model".to_string(),
user_input: vec![UserInput::Text {
text: "$first".to_string(),
text_elements: Vec::new(),
}],
reserved_plain_tool_names: Default::default(),
environments: Vec::new(),
},
&session_store,
@@ -390,6 +460,7 @@ async fn root_qualified_locator_selects_only_the_matching_executor_skill() -> Te
.collect(),
warnings: Vec::new(),
},
contents: STATIC_SKILL_CONTENTS.to_string(),
read_requests: Arc::clone(&read_requests),
list_calls: None,
fail_first_list: false,
@@ -430,10 +501,12 @@ async fn root_qualified_locator_selects_only_the_matching_executor_skill() -> Te
TurnInputContext {
thread_id: ThreadId::default(),
turn_id: "turn-1".to_string(),
model: "test-model".to_string(),
user_input: vec![UserInput::Mention {
name: "lint-fix".to_string(),
path: root_b_locator.to_string(),
}],
reserved_plain_tool_names: Default::default(),
environments: Vec::new(),
},
&session_store,
@@ -463,26 +536,27 @@ async fn prompt_hidden_skill_can_still_be_invoked() -> TestResult {
catalog: SkillCatalog {
entries: vec![
test_entry(
SkillSourceKind::Orchestrator,
"codex_apps",
"orchestrator/visible-skill",
"skill://orchestrator/visible-skill/SKILL.md",
SkillSourceKind::Host,
"host",
"host/visible-skill",
"visible-skill/SKILL.md",
),
test_entry(
SkillSourceKind::Orchestrator,
"codex_apps",
"orchestrator/hidden-skill",
"skill://orchestrator/hidden-skill/SKILL.md",
SkillSourceKind::Host,
"host",
"host/hidden-skill",
"hidden-skill/SKILL.md",
)
.hidden_from_prompt(),
],
warnings: Vec::new(),
},
contents: STATIC_SKILL_CONTENTS.to_string(),
read_requests: Arc::clone(&read_requests),
list_calls: None,
fail_first_list: false,
});
let providers = SkillProviders::new().with_orchestrator_provider(provider);
let providers = SkillProviders::new().with_host_provider(provider);
let mut builder = ExtensionRegistryBuilder::new();
install_with_providers(&mut builder, providers, skills_extension_config);
let registry = builder.build();
@@ -517,10 +591,12 @@ async fn prompt_hidden_skill_can_still_be_invoked() -> TestResult {
TurnInputContext {
thread_id: ThreadId::default(),
turn_id: "turn-1".to_string(),
model: "test-model".to_string(),
user_input: vec![UserInput::Text {
text: "$hidden-skill".to_string(),
text_elements: Vec::new(),
}],
reserved_plain_tool_names: Default::default(),
environments: Vec::new(),
},
&session_store,
@@ -533,9 +609,9 @@ async fn prompt_hidden_skill_can_still_be_invoked() -> TestResult {
assert!(fragments[0].render().contains("<name>hidden-skill</name>"));
assert_eq!(
vec![(
SkillAuthority::new(SkillSourceKind::Orchestrator, "codex_apps"),
SkillPackageId("orchestrator/hidden-skill".to_string()),
SkillResourceId::new("skill://orchestrator/hidden-skill/SKILL.md"),
SkillAuthority::new(SkillSourceKind::Host, "host"),
SkillPackageId("host/hidden-skill".to_string()),
SkillResourceId::new("hidden-skill/SKILL.md"),
)],
read_request_keys(&read_requests)
);
@@ -543,9 +619,207 @@ async fn prompt_hidden_skill_can_still_be_invoked() -> TestResult {
Ok(())
}
#[tokio::test]
async fn host_plain_mentions_preserve_legacy_disambiguation() -> TestResult {
let read_requests = Arc::new(Mutex::new(Vec::new()));
let calendar_locator = "skill://host/calendar/SKILL.md";
let provider = Arc::new(StaticSkillProvider {
catalog: SkillCatalog {
entries: vec![
SkillCatalogEntry::new(
SkillPackageId("host/deploy-user".to_string()),
SkillAuthority::new(SkillSourceKind::Host, "host"),
"deploy",
"Deploy from the user scope.",
SkillResourceId::new("deploy-user/SKILL.md"),
),
SkillCatalogEntry::new(
SkillPackageId("host/deploy-repo".to_string()),
SkillAuthority::new(SkillSourceKind::Host, "host"),
"deploy",
"Deploy from the repo scope.",
SkillResourceId::new("deploy-repo/SKILL.md"),
),
SkillCatalogEntry::new(
SkillPackageId("host/calendar".to_string()),
SkillAuthority::new(SkillSourceKind::Host, "host"),
"calendar",
"Use the calendar skill.",
SkillResourceId::new("calendar/SKILL.md"),
)
.with_display_path(calendar_locator),
],
warnings: Vec::new(),
},
contents: STATIC_SKILL_CONTENTS.to_string(),
read_requests: Arc::clone(&read_requests),
list_calls: None,
fail_first_list: false,
});
let providers = SkillProviders::new().with_host_provider(provider);
let mut builder = ExtensionRegistryBuilder::new();
install_with_providers(&mut builder, providers, skills_extension_config);
let registry = builder.build();
let session_store = ExtensionData::new("session");
let thread_store = ExtensionData::new("thread");
let session_source = SessionSource::Cli;
let config = default_config();
registry.thread_lifecycle_contributors()[0]
.on_thread_start(ThreadStartInput {
config: &config,
session_source: &session_source,
persistent_thread_state_available: true,
environments: &[],
session_store: &session_store,
thread_store: &thread_store,
})
.await;
let ambiguous_fragments = registry.turn_input_contributors()[0]
.contribute(
TurnInputContext {
thread_id: ThreadId::default(),
turn_id: "turn-ambiguous".to_string(),
model: "test-model".to_string(),
user_input: vec![UserInput::Text {
text: "$deploy".to_string(),
text_elements: Vec::new(),
}],
reserved_plain_tool_names: Default::default(),
environments: Vec::new(),
},
&session_store,
&thread_store,
&ExtensionData::new("turn-ambiguous"),
)
.await;
assert!(ambiguous_fragments.is_empty());
let connector_conflict_fragments = registry.turn_input_contributors()[0]
.contribute(
TurnInputContext {
thread_id: ThreadId::default(),
turn_id: "turn-connector-conflict".to_string(),
model: "test-model".to_string(),
user_input: vec![UserInput::Text {
text: "$calendar".to_string(),
text_elements: Vec::new(),
}],
reserved_plain_tool_names: ["calendar".to_string()].into_iter().collect(),
environments: Vec::new(),
},
&session_store,
&thread_store,
&ExtensionData::new("turn-connector-conflict"),
)
.await;
assert!(connector_conflict_fragments.is_empty());
let explicit_fragments = registry.turn_input_contributors()[0]
.contribute(
TurnInputContext {
thread_id: ThreadId::default(),
turn_id: "turn-explicit".to_string(),
model: "test-model".to_string(),
user_input: vec![UserInput::Mention {
name: "calendar".to_string(),
path: calendar_locator.to_string(),
}],
reserved_plain_tool_names: ["calendar".to_string()].into_iter().collect(),
environments: Vec::new(),
},
&session_store,
&thread_store,
&ExtensionData::new("turn-explicit"),
)
.await;
assert_eq!(1, explicit_fragments.len());
assert_eq!(
vec![(
SkillAuthority::new(SkillSourceKind::Host, "host"),
SkillPackageId("host/calendar".to_string()),
SkillResourceId::new("calendar/SKILL.md"),
)],
read_request_keys(&read_requests)
);
Ok(())
}
#[tokio::test]
async fn connector_mentions_only_include_injected_skill_text() -> TestResult {
let provider = Arc::new(StaticSkillProvider {
catalog: SkillCatalog {
entries: vec![test_entry(
SkillSourceKind::Executor,
"env-1",
"executor/lint-fix",
"lint-fix/SKILL.md",
)],
warnings: Vec::new(),
},
contents: format!("{}[$calendar](app://calendar)", "x".repeat(9_000)),
read_requests: Arc::new(Mutex::new(Vec::new())),
list_calls: None,
fail_first_list: false,
});
let providers = SkillProviders::new().with_executor_provider(provider);
let mut builder = ExtensionRegistryBuilder::new();
install_with_providers(&mut builder, providers, skills_extension_config);
let registry = builder.build();
let session_store = ExtensionData::new("session");
let thread_store = ExtensionData::new("thread");
thread_store.insert(vec![SelectedCapabilityRoot {
id: "lint-fix".to_string(),
location: CapabilityRootLocation::Environment {
environment_id: "env-1".to_string(),
path: "/skills/lint-fix".to_string(),
},
}]);
let session_source = SessionSource::Cli;
let config = default_config();
registry.thread_lifecycle_contributors()[0]
.on_thread_start(ThreadStartInput {
config: &config,
session_source: &session_source,
persistent_thread_state_available: true,
environments: &[],
session_store: &session_store,
thread_store: &thread_store,
})
.await;
let turn_store = ExtensionData::new("turn-1");
let fragments = registry.turn_input_contributors()[0]
.contribute(
TurnInputContext {
thread_id: ThreadId::default(),
turn_id: "turn-1".to_string(),
model: "test-model".to_string(),
user_input: vec![UserInput::Text {
text: "$lint-fix".to_string(),
text_elements: Vec::new(),
}],
reserved_plain_tool_names: Default::default(),
environments: Vec::new(),
},
&session_store,
&thread_store,
&turn_store,
)
.await;
assert_eq!(1, fragments.len());
assert!(!fragments[0].render().contains("app://calendar"));
assert!(turn_store.get::<ExplicitConnectorMentions>().is_none());
Ok(())
}
#[derive(Clone)]
struct StaticSkillProvider {
catalog: SkillCatalog,
contents: String,
read_requests: Arc<Mutex<Vec<SkillReadRequest>>>,
list_calls: Option<Arc<AtomicUsize>>,
fail_first_list: bool,
@@ -577,6 +851,7 @@ impl SkillProvider for StaticSkillProvider {
}
fn read(&self, request: SkillReadRequest) -> SkillProviderFuture<'_, SkillReadResult> {
let contents = self.contents.clone();
let read_requests = Arc::clone(&self.read_requests);
Box::pin(async move {
read_requests
@@ -585,7 +860,7 @@ impl SkillProvider for StaticSkillProvider {
.push(request.clone());
Ok(SkillReadResult {
resource: request.resource,
contents: "# Lint Fix\n\nRun the formatter.".to_string(),
contents,
})
})
}