mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
codex: address skills path review feedback
This commit is contained in:
@@ -3011,13 +3011,6 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"environmentId": {
|
||||
"description": "Environment whose filesystem should be used for all requested cwd values.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"forceReload": {
|
||||
"description": "When true, bypass the skills cache and re-scan skills from disk.",
|
||||
"type": "boolean"
|
||||
|
||||
-7
@@ -15201,13 +15201,6 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"environmentId": {
|
||||
"description": "Environment whose filesystem should be used for all requested cwd values.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"forceReload": {
|
||||
"description": "When true, bypass the skills cache and re-scan skills from disk.",
|
||||
"type": "boolean"
|
||||
|
||||
-7
@@ -13025,13 +13025,6 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"environmentId": {
|
||||
"description": "Environment whose filesystem should be used for all requested cwd values.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"forceReload": {
|
||||
"description": "When true, bypass the skills cache and re-scan skills from disk.",
|
||||
"type": "boolean"
|
||||
|
||||
@@ -8,13 +8,6 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"environmentId": {
|
||||
"description": "Environment whose filesystem should be used for all requested cwd values.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"forceReload": {
|
||||
"description": "When true, bypass the skills cache and re-scan skills from disk.",
|
||||
"type": "boolean"
|
||||
|
||||
@@ -7,10 +7,6 @@ export type SkillsListParams = {
|
||||
* When empty, defaults to the current session working directory.
|
||||
*/
|
||||
cwds?: Array<string>,
|
||||
/**
|
||||
* Environment whose filesystem should be used for all requested cwd values.
|
||||
*/
|
||||
environmentId?: string | null,
|
||||
/**
|
||||
* When true, bypass the skills cache and re-scan skills from disk.
|
||||
*/
|
||||
|
||||
@@ -1718,7 +1718,6 @@ mod tests {
|
||||
request_id: request_id(),
|
||||
params: v2::SkillsListParams {
|
||||
cwds: Vec::new(),
|
||||
environment_id: None,
|
||||
force_reload: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -23,10 +23,6 @@ pub struct SkillsListParams {
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub cwds: Vec<PathBuf>,
|
||||
|
||||
/// Environment whose filesystem should be used for all requested cwd values.
|
||||
#[ts(optional = nullable)]
|
||||
pub environment_id: Option<String>,
|
||||
|
||||
/// When true, bypass the skills cache and re-scan skills from disk.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub force_reload: bool,
|
||||
|
||||
@@ -2607,41 +2607,23 @@ fn skills_list_params_serialization_uses_force_reload() {
|
||||
assert_eq!(
|
||||
serde_json::to_value(SkillsListParams {
|
||||
cwds: Vec::new(),
|
||||
environment_id: None,
|
||||
force_reload: false,
|
||||
})
|
||||
.unwrap(),
|
||||
json!({
|
||||
"environmentId": null,
|
||||
}),
|
||||
json!({}),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_value(SkillsListParams {
|
||||
cwds: vec![PathBuf::from("/repo")],
|
||||
environment_id: None,
|
||||
force_reload: true,
|
||||
})
|
||||
.unwrap(),
|
||||
json!({
|
||||
"cwds": ["/repo"],
|
||||
"environmentId": null,
|
||||
"forceReload": true,
|
||||
}),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
serde_json::to_value(SkillsListParams {
|
||||
cwds: vec![PathBuf::from("/repo")],
|
||||
environment_id: Some("devbox".to_string()),
|
||||
force_reload: false,
|
||||
})
|
||||
.unwrap(),
|
||||
json!({
|
||||
"cwds": ["/repo"],
|
||||
"environmentId": "devbox",
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1504,14 +1504,13 @@ Example:
|
||||
$skill-creator Add a new skill for triaging flaky CI and include step-by-step usage.
|
||||
```
|
||||
|
||||
Use `skills/list` to fetch the available skills (optionally scoped by `cwds`, `environmentId`, and `forceReload`).
|
||||
Use `skills/list` to fetch the available skills (optionally scoped by `cwds`, with `forceReload`).
|
||||
`skills/list` might reuse a cached skills result per `cwd`; setting `forceReload` to `true` refreshes the result from disk.
|
||||
The server also emits `skills/changed` notifications when watched local skill files change. Treat this as an invalidation signal and re-run `skills/list` with your current params when needed.
|
||||
Use `skills/extraRoots/set` to replace additional standalone skill roots for the current app-server process. These roots use the same layout as other standalone skill roots: each root contains skill directories, and each skill directory contains `SKILL.md`. Missing roots are accepted and load no skills until they exist. This setting is lost when app-server exits.
|
||||
|
||||
```json
|
||||
{ "method": "skills/list", "id": 25, "params": {
|
||||
"environmentId": "local",
|
||||
"cwds": ["/Users/me/project", "/Users/me/other-project"],
|
||||
"forceReload": true
|
||||
} }
|
||||
|
||||
@@ -17,12 +17,12 @@ const SKILLS_LIST_CWD_CONCURRENCY: usize = 5;
|
||||
|
||||
fn skills_to_info(
|
||||
skills: &[codex_core::skills::SkillMetadata],
|
||||
disabled_paths: &HashSet<AbsolutePathBuf>,
|
||||
disabled_paths: &HashSet<codex_exec_server::EnvironmentPathRef>,
|
||||
) -> Vec<codex_app_server_protocol::SkillMetadata> {
|
||||
skills
|
||||
.iter()
|
||||
.map(|skill| {
|
||||
let enabled = !disabled_paths.contains(&skill.path_to_skills_md);
|
||||
let enabled = !disabled_paths.contains(&skill.source_path);
|
||||
codex_app_server_protocol::SkillMetadata {
|
||||
name: skill.name.clone(),
|
||||
description: skill.description.clone(),
|
||||
@@ -499,11 +499,7 @@ impl CatalogRequestProcessor {
|
||||
&self,
|
||||
params: SkillsListParams,
|
||||
) -> Result<SkillsListResponse, JSONRPCErrorError> {
|
||||
let SkillsListParams {
|
||||
cwds,
|
||||
environment_id,
|
||||
force_reload,
|
||||
} = params;
|
||||
let SkillsListParams { cwds, force_reload } = params;
|
||||
let cwds = if cwds.is_empty() {
|
||||
vec![self.config.cwd.to_path_buf()]
|
||||
} else {
|
||||
@@ -518,22 +514,11 @@ impl CatalogRequestProcessor {
|
||||
let skills_manager = self.thread_manager.skills_manager();
|
||||
let plugins_manager = self.thread_manager.plugins_manager();
|
||||
let environment_manager = self.thread_manager.environment_manager();
|
||||
let selected_environment = match environment_id {
|
||||
Some(environment_id) => {
|
||||
let environment = environment_manager
|
||||
.get_environment(&environment_id)
|
||||
.ok_or_else(|| {
|
||||
invalid_request(format!(
|
||||
"unknown skills/list environment id `{environment_id}`"
|
||||
))
|
||||
})?;
|
||||
Some(environment)
|
||||
}
|
||||
None => environment_manager.try_local_environment(),
|
||||
};
|
||||
let local_file_system = environment_manager
|
||||
.try_local_environment()
|
||||
.map(|environment| environment.get_filesystem());
|
||||
// TODO: Reintroduce env-scoped `skills/list` only after cwd/config-layer discovery can run
|
||||
// against the selected environment and the design decides which non-repo roots stay local
|
||||
// versus follow that environment.
|
||||
let selected_environment = environment_manager.default_environment();
|
||||
let local_file_system = Some(Arc::clone(&codex_exec_server::LOCAL_FS));
|
||||
let mut data = futures::stream::iter(cwds.into_iter().enumerate())
|
||||
.map(|(index, cwd)| {
|
||||
let config = &config;
|
||||
@@ -570,24 +555,13 @@ impl CatalogRequestProcessor {
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
let Some(environment) = selected_environment.as_ref() else {
|
||||
// Omitted `environmentId` uses the legacy implicit local target. When
|
||||
// local exec is disabled there is no valid implicit target, so return an
|
||||
// empty catalog rather than silently switching to the default environment.
|
||||
return (
|
||||
index,
|
||||
codex_app_server_protocol::SkillsListEntry {
|
||||
cwd,
|
||||
skills: Vec::new(),
|
||||
errors: Vec::new(),
|
||||
},
|
||||
);
|
||||
};
|
||||
let skills_input = codex_core::skills::SkillsLoadInput::new(
|
||||
codex_exec_server::EnvironmentPathRef::new(
|
||||
environment.get_filesystem(),
|
||||
cwd_abs.clone(),
|
||||
),
|
||||
selected_environment.as_ref().map(|environment| {
|
||||
codex_exec_server::EnvironmentPathRef::new(
|
||||
environment.get_filesystem(),
|
||||
cwd_abs.clone(),
|
||||
)
|
||||
}),
|
||||
local_file_system,
|
||||
effective_skill_roots,
|
||||
config_layer_stack,
|
||||
|
||||
@@ -103,15 +103,12 @@ impl SkillsWatcher {
|
||||
|
||||
let root_path_ref =
|
||||
EnvironmentPathRef::new(environment.get_filesystem(), config.cwd.clone());
|
||||
let local_file_system = thread_manager
|
||||
.environment_manager()
|
||||
.try_local_environment()
|
||||
.map(|environment| environment.get_filesystem());
|
||||
let local_file_system = Some(Arc::clone(&codex_exec_server::LOCAL_FS));
|
||||
let plugins_input = config.plugins_config_input();
|
||||
let plugins_manager = thread_manager.plugins_manager();
|
||||
let plugin_outcome = plugins_manager.plugins_for_config(&plugins_input).await;
|
||||
let skills_input = SkillsLoadInput::new(
|
||||
root_path_ref,
|
||||
Some(root_path_ref),
|
||||
local_file_system,
|
||||
plugin_outcome.effective_plugin_skill_roots(),
|
||||
config.config_layer_stack.clone(),
|
||||
|
||||
@@ -20,7 +20,6 @@ use codex_app_server_protocol::SkillsListResponse;
|
||||
use codex_app_server_protocol::ThreadStartParams;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_exec_server::CODEX_EXEC_SERVER_URL_ENV_VAR;
|
||||
use codex_exec_server::LOCAL_ENVIRONMENT_ID;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
@@ -249,7 +248,6 @@ async fn skills_list_loads_remote_installed_plugin_skills_from_cache() -> Result
|
||||
let stale_skills_list_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![cwd.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: true,
|
||||
})
|
||||
.await?;
|
||||
@@ -300,7 +298,6 @@ async fn skills_list_loads_remote_installed_plugin_skills_from_cache() -> Result
|
||||
let skills_list_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![cwd.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: false,
|
||||
})
|
||||
.await?;
|
||||
@@ -375,7 +372,6 @@ async fn skills_list_excludes_plugin_skills_when_workspace_codex_plugins_disable
|
||||
let request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![repo_root.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: true,
|
||||
})
|
||||
.await?;
|
||||
@@ -405,7 +401,7 @@ async fn skills_list_excludes_plugin_skills_when_workspace_codex_plugins_disable
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn skills_list_returns_empty_when_implicit_local_environment_is_disabled() -> Result<()> {
|
||||
async fn skills_list_skips_cwd_roots_when_environment_disabled() -> Result<()> {
|
||||
let codex_home = TempDir::new()?;
|
||||
let cwd = TempDir::new()?;
|
||||
write_skill(&codex_home, "home-skill")?;
|
||||
@@ -426,7 +422,6 @@ async fn skills_list_returns_empty_when_implicit_local_environment_is_disabled()
|
||||
let request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![cwd.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: true,
|
||||
})
|
||||
.await?;
|
||||
@@ -440,7 +435,18 @@ async fn skills_list_returns_empty_when_implicit_local_environment_is_disabled()
|
||||
assert_eq!(data.len(), 1);
|
||||
assert_eq!(data[0].cwd, cwd.path().to_path_buf());
|
||||
assert_eq!(data[0].errors, Vec::new());
|
||||
assert_eq!(data[0].skills, Vec::new());
|
||||
assert!(
|
||||
data[0]
|
||||
.skills
|
||||
.iter()
|
||||
.any(|skill| skill.name == "home-skill")
|
||||
);
|
||||
assert!(
|
||||
data[0]
|
||||
.skills
|
||||
.iter()
|
||||
.all(|skill| skill.name != "repo-skill")
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -456,7 +462,6 @@ async fn skills_list_accepts_relative_cwds() -> Result<()> {
|
||||
let request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![relative_cwd.clone()],
|
||||
environment_id: Some(LOCAL_ENVIRONMENT_ID.to_string()),
|
||||
force_reload: true,
|
||||
})
|
||||
.await?;
|
||||
@@ -488,7 +493,6 @@ async fn skills_list_preserves_requested_cwd_order() -> Result<()> {
|
||||
first_cwd.path().to_path_buf(),
|
||||
second_cwd.path().to_path_buf(),
|
||||
],
|
||||
environment_id: None,
|
||||
force_reload: true,
|
||||
})
|
||||
.await?;
|
||||
@@ -523,7 +527,6 @@ async fn skills_list_uses_cached_result_until_force_reload() -> Result<()> {
|
||||
let first_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![cwd.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: false,
|
||||
})
|
||||
.await?;
|
||||
@@ -551,7 +554,6 @@ async fn skills_list_uses_cached_result_until_force_reload() -> Result<()> {
|
||||
let second_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![cwd.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: false,
|
||||
})
|
||||
.await?;
|
||||
@@ -572,7 +574,6 @@ async fn skills_list_uses_cached_result_until_force_reload() -> Result<()> {
|
||||
let third_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![cwd.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: true,
|
||||
})
|
||||
.await?;
|
||||
@@ -624,7 +625,6 @@ async fn skills_extra_roots_set_updates_process_runtime_roots() -> Result<()> {
|
||||
let skills_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![cwd.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: false,
|
||||
})
|
||||
.await?;
|
||||
@@ -660,7 +660,6 @@ async fn skills_extra_roots_set_updates_process_runtime_roots() -> Result<()> {
|
||||
let skills_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![cwd.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: false,
|
||||
})
|
||||
.await?;
|
||||
@@ -694,7 +693,6 @@ async fn skills_extra_roots_set_updates_process_runtime_roots() -> Result<()> {
|
||||
let skills_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![cwd.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: false,
|
||||
})
|
||||
.await?;
|
||||
@@ -719,7 +717,6 @@ async fn skills_extra_roots_set_updates_process_runtime_roots() -> Result<()> {
|
||||
let skills_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![cwd.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: false,
|
||||
})
|
||||
.await?;
|
||||
@@ -758,7 +755,6 @@ async fn skills_changed_notification_is_emitted_after_skill_change() -> Result<(
|
||||
let initial_skills_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![codex_home.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: true,
|
||||
})
|
||||
.await?;
|
||||
@@ -832,7 +828,6 @@ async fn skills_changed_notification_is_emitted_after_skill_change() -> Result<(
|
||||
let updated_skills_request_id = mcp
|
||||
.send_skills_list_request(SkillsListParams {
|
||||
cwds: vec![codex_home.path().to_path_buf()],
|
||||
environment_id: None,
|
||||
force_reload: false,
|
||||
})
|
||||
.await?;
|
||||
|
||||
@@ -665,7 +665,10 @@ pub async fn load_plugin_skills(
|
||||
.into_iter()
|
||||
.filter(|skill| skill.matches_product_restriction_for_product(restriction_product))
|
||||
.collect::<Vec<_>>();
|
||||
let disabled_skill_paths = resolve_disabled_skill_paths(&skills, skill_config_rules);
|
||||
let disabled_skill_paths = resolve_disabled_skill_paths(&skills, skill_config_rules)
|
||||
.into_iter()
|
||||
.map(|path| path.path().clone())
|
||||
.collect();
|
||||
|
||||
ResolvedPluginSkills {
|
||||
skills,
|
||||
|
||||
@@ -5,6 +5,7 @@ use codex_config::ConfigLayerStack;
|
||||
use codex_config::ConfigLayerStackOrdering;
|
||||
use codex_config::SkillConfig;
|
||||
use codex_config::SkillsConfig;
|
||||
use codex_exec_server::EnvironmentPathRef;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use tracing::warn;
|
||||
|
||||
@@ -71,28 +72,34 @@ pub fn skill_config_rules_from_stack(config_layer_stack: &ConfigLayerStack) -> S
|
||||
pub fn resolve_disabled_skill_paths(
|
||||
skills: &[SkillMetadata],
|
||||
rules: &SkillConfigRules,
|
||||
) -> HashSet<AbsolutePathBuf> {
|
||||
) -> HashSet<EnvironmentPathRef> {
|
||||
let mut disabled_paths = HashSet::new();
|
||||
|
||||
for entry in &rules.entries {
|
||||
match &entry.selector {
|
||||
SkillConfigRuleSelector::Path(path) => {
|
||||
if entry.enabled {
|
||||
disabled_paths.remove(path);
|
||||
} else {
|
||||
disabled_paths.insert(path.clone());
|
||||
for source_path in skills
|
||||
.iter()
|
||||
.filter(|skill| skill.path_to_skills_md == *path)
|
||||
.map(|skill| skill.source_path.clone())
|
||||
{
|
||||
if entry.enabled {
|
||||
disabled_paths.remove(&source_path);
|
||||
} else {
|
||||
disabled_paths.insert(source_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
SkillConfigRuleSelector::Name(name) => {
|
||||
for path in skills
|
||||
for source_path in skills
|
||||
.iter()
|
||||
.filter(|skill| skill.name == *name)
|
||||
.map(|skill| skill.path_to_skills_md.clone())
|
||||
.map(|skill| skill.source_path.clone())
|
||||
{
|
||||
if entry.enabled {
|
||||
disabled_paths.remove(&path);
|
||||
disabled_paths.remove(&source_path);
|
||||
} else {
|
||||
disabled_paths.insert(path);
|
||||
disabled_paths.insert(source_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::SkillLoadOutcome;
|
||||
use crate::SkillMetadata;
|
||||
use crate::build_skill_name_counts;
|
||||
@@ -9,11 +5,13 @@ use codex_analytics::AnalyticsEventsClient;
|
||||
use codex_analytics::InvocationType;
|
||||
use codex_analytics::SkillInvocation;
|
||||
use codex_analytics::TrackEventsContext;
|
||||
use codex_exec_server::LOCAL_FS;
|
||||
use codex_exec_server::EnvironmentPathRef;
|
||||
use codex_otel::SessionTelemetry;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_plugins::mention_syntax::TOOL_MENTION_SIGIL;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct SkillInjections {
|
||||
@@ -30,7 +28,7 @@ pub struct SkillInjection {
|
||||
|
||||
pub async fn build_skill_injections(
|
||||
mentioned_skills: &[SkillMetadata],
|
||||
loaded_skills: Option<&SkillLoadOutcome>,
|
||||
_loaded_skills: Option<&SkillLoadOutcome>,
|
||||
otel: Option<&SessionTelemetry>,
|
||||
analytics_client: &AnalyticsEventsClient,
|
||||
tracking: TrackEventsContext,
|
||||
@@ -46,13 +44,7 @@ pub async fn build_skill_injections(
|
||||
let mut invocations = Vec::new();
|
||||
|
||||
for skill in mentioned_skills {
|
||||
let fs = loaded_skills
|
||||
.and_then(|outcome| outcome.file_system_for_skill(skill))
|
||||
.unwrap_or_else(|| Arc::clone(&LOCAL_FS));
|
||||
match fs
|
||||
.read_file_text(&skill.path_to_skills_md, /*sandbox*/ None)
|
||||
.await
|
||||
{
|
||||
match skill.source_path.read_to_string(/*sandbox*/ None).await {
|
||||
Ok(contents) => {
|
||||
emit_skill_injected_metric(otel, skill, "ok");
|
||||
invocations.push(SkillInvocation {
|
||||
@@ -115,7 +107,7 @@ fn emit_skill_injected_metric(
|
||||
pub fn collect_explicit_skill_mentions(
|
||||
inputs: &[UserInput],
|
||||
skills: &[SkillMetadata],
|
||||
disabled_paths: &HashSet<AbsolutePathBuf>,
|
||||
disabled_paths: &HashSet<EnvironmentPathRef>,
|
||||
connector_slug_counts: &HashMap<String, usize>,
|
||||
) -> Vec<SkillMetadata> {
|
||||
let skill_name_counts = build_skill_name_counts(skills, disabled_paths).0;
|
||||
@@ -128,7 +120,7 @@ pub fn collect_explicit_skill_mentions(
|
||||
};
|
||||
let mut selected: Vec<SkillMetadata> = Vec::new();
|
||||
let mut seen_names: HashSet<String> = HashSet::new();
|
||||
let mut seen_paths: HashSet<AbsolutePathBuf> = HashSet::new();
|
||||
let mut seen_paths: HashSet<EnvironmentPathRef> = HashSet::new();
|
||||
let mut blocked_plain_names: HashSet<String> = HashSet::new();
|
||||
|
||||
for input in inputs {
|
||||
@@ -138,18 +130,22 @@ pub fn collect_explicit_skill_mentions(
|
||||
continue;
|
||||
};
|
||||
|
||||
if selection_context.disabled_paths.contains(&path) || seen_paths.contains(&path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(skill) = selection_context
|
||||
let matching_skills = selection_context
|
||||
.skills
|
||||
.iter()
|
||||
.find(|skill| skill.path_to_skills_md == path)
|
||||
.filter(|skill| {
|
||||
skill.path_to_skills_md == path
|
||||
&& !selection_context
|
||||
.disabled_paths
|
||||
.contains(&skill.source_path)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
if let [skill] = matching_skills.as_slice()
|
||||
&& !seen_paths.contains(&skill.source_path)
|
||||
{
|
||||
seen_paths.insert(skill.path_to_skills_md.clone());
|
||||
seen_paths.insert(skill.source_path.clone());
|
||||
seen_names.insert(skill.name.clone());
|
||||
selected.push(skill.clone());
|
||||
selected.push((*skill).clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,7 +169,7 @@ pub fn collect_explicit_skill_mentions(
|
||||
|
||||
struct SkillSelectionContext<'a> {
|
||||
skills: &'a [SkillMetadata],
|
||||
disabled_paths: &'a HashSet<AbsolutePathBuf>,
|
||||
disabled_paths: &'a HashSet<EnvironmentPathRef>,
|
||||
skill_name_counts: &'a HashMap<String, usize>,
|
||||
connector_slug_counts: &'a HashMap<String, usize>,
|
||||
}
|
||||
@@ -324,7 +320,7 @@ fn select_skills_from_mentions(
|
||||
blocked_plain_names: &HashSet<String>,
|
||||
mentions: &ToolMentions<'_>,
|
||||
seen_names: &mut HashSet<String>,
|
||||
seen_paths: &mut HashSet<AbsolutePathBuf>,
|
||||
seen_paths: &mut HashSet<EnvironmentPathRef>,
|
||||
selected: &mut Vec<SkillMetadata>,
|
||||
) {
|
||||
if mentions.is_empty() {
|
||||
@@ -342,18 +338,39 @@ fn select_skills_from_mentions(
|
||||
.map(normalize_skill_path)
|
||||
.collect();
|
||||
|
||||
let mention_skill_path_counts = selection_context
|
||||
.skills
|
||||
.iter()
|
||||
.filter(|skill| {
|
||||
!selection_context
|
||||
.disabled_paths
|
||||
.contains(&skill.source_path)
|
||||
})
|
||||
.filter_map(|skill| {
|
||||
let path = skill.path_to_skills_md.to_string_lossy();
|
||||
mention_skill_paths
|
||||
.contains(path.as_ref())
|
||||
.then_some(path.into_owned())
|
||||
})
|
||||
.fold(HashMap::new(), |mut counts, path| {
|
||||
*counts.entry(path).or_insert(0usize) += 1;
|
||||
counts
|
||||
});
|
||||
|
||||
for skill in selection_context.skills {
|
||||
if selection_context
|
||||
.disabled_paths
|
||||
.contains(&skill.path_to_skills_md)
|
||||
|| seen_paths.contains(&skill.path_to_skills_md)
|
||||
.contains(&skill.source_path)
|
||||
|| seen_paths.contains(&skill.source_path)
|
||||
{
|
||||
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());
|
||||
if mention_skill_paths.contains(path_str.as_ref())
|
||||
&& mention_skill_path_counts.get(path_str.as_ref()) == Some(&1)
|
||||
{
|
||||
seen_paths.insert(skill.source_path.clone());
|
||||
seen_names.insert(skill.name.clone());
|
||||
selected.push(skill.clone());
|
||||
}
|
||||
@@ -362,8 +379,8 @@ fn select_skills_from_mentions(
|
||||
for skill in selection_context.skills {
|
||||
if selection_context
|
||||
.disabled_paths
|
||||
.contains(&skill.path_to_skills_md)
|
||||
|| seen_paths.contains(&skill.path_to_skills_md)
|
||||
.contains(&skill.source_path)
|
||||
|| seen_paths.contains(&skill.source_path)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -390,7 +407,7 @@ fn select_skills_from_mentions(
|
||||
}
|
||||
|
||||
if seen_names.insert(skill.name.clone()) {
|
||||
seen_paths.insert(skill.path_to_skills_md.clone());
|
||||
seen_paths.insert(skill.source_path.clone());
|
||||
selected.push(skill.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::*;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_exec_server::EnvironmentPathRef;
|
||||
use codex_exec_server::LocalFileSystem;
|
||||
use codex_utils_absolute_path::test_support::PathBufExt;
|
||||
use codex_utils_absolute_path::test_support::test_path_buf;
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -14,6 +15,7 @@ fn make_skill(name: &str, path: &str) -> SkillMetadata {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(test_path_buf(path).abs()),
|
||||
path_to_skills_md: test_path_buf(path).abs(),
|
||||
scope: codex_protocol::protocol::SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -37,7 +39,7 @@ fn linked_skill_mention(name: &str, unix_path: &str) -> String {
|
||||
fn collect_mentions(
|
||||
inputs: &[UserInput],
|
||||
skills: &[SkillMetadata],
|
||||
disabled_paths: &HashSet<AbsolutePathBuf>,
|
||||
disabled_paths: &HashSet<EnvironmentPathRef>,
|
||||
connector_slug_counts: &HashMap<String, usize>,
|
||||
) -> Vec<SkillMetadata> {
|
||||
collect_explicit_skill_mentions(inputs, skills, disabled_paths, connector_slug_counts)
|
||||
@@ -193,6 +195,7 @@ fn collect_explicit_skill_mentions_skips_invalid_structured_and_blocks_plain_fal
|
||||
#[test]
|
||||
fn collect_explicit_skill_mentions_skips_disabled_structured_and_blocks_plain_fallback() {
|
||||
let alpha = make_skill("alpha-skill", "/tmp/alpha");
|
||||
let disabled = HashSet::from([alpha.source_path.clone()]);
|
||||
let skills = vec![alpha];
|
||||
let inputs = vec![
|
||||
UserInput::Text {
|
||||
@@ -204,7 +207,6 @@ fn collect_explicit_skill_mentions_skips_disabled_structured_and_blocks_plain_fa
|
||||
path: test_path_buf("/tmp/alpha"),
|
||||
},
|
||||
];
|
||||
let disabled = HashSet::from([test_path_buf("/tmp/alpha").abs()]);
|
||||
let connector_counts = HashMap::new();
|
||||
|
||||
let selected = collect_mentions(&inputs, &skills, &disabled, &connector_counts);
|
||||
@@ -228,6 +230,29 @@ fn collect_explicit_skill_mentions_dedupes_by_path() {
|
||||
assert_eq!(selected, vec![alpha]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_explicit_skill_mentions_skips_ambiguous_linked_path() {
|
||||
let alpha = make_skill("demo-skill", "/tmp/shared");
|
||||
let beta = SkillMetadata {
|
||||
name: "demo-skill".to_string(),
|
||||
source_path: EnvironmentPathRef::new(
|
||||
std::sync::Arc::new(LocalFileSystem::unsandboxed()),
|
||||
alpha.path_to_skills_md.clone(),
|
||||
),
|
||||
..alpha.clone()
|
||||
};
|
||||
let skills = vec![alpha, beta];
|
||||
let inputs = vec![UserInput::Text {
|
||||
text: linked_skill_mention("demo-skill", "/tmp/shared"),
|
||||
text_elements: Vec::new(),
|
||||
}];
|
||||
let connector_counts = HashMap::new();
|
||||
|
||||
let selected = collect_mentions(&inputs, &skills, &HashSet::new(), &connector_counts);
|
||||
|
||||
assert_eq!(selected, Vec::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_explicit_skill_mentions_skips_ambiguous_name() {
|
||||
let alpha = make_skill("demo-skill", "/tmp/alpha");
|
||||
@@ -297,12 +322,12 @@ fn collect_explicit_skill_mentions_allows_explicit_path_with_connector_conflict(
|
||||
fn collect_explicit_skill_mentions_skips_when_linked_path_disabled() {
|
||||
let alpha = make_skill("demo-skill", "/tmp/alpha");
|
||||
let beta = make_skill("demo-skill", "/tmp/beta");
|
||||
let disabled = HashSet::from([alpha.source_path.clone()]);
|
||||
let skills = vec![alpha, beta];
|
||||
let inputs = vec![UserInput::Text {
|
||||
text: format!("use {}", linked_skill_mention("demo-skill", "/tmp/alpha")),
|
||||
text_elements: Vec::new(),
|
||||
}];
|
||||
let disabled = HashSet::from([test_path_buf("/tmp/alpha").abs()]);
|
||||
let connector_counts = HashMap::new();
|
||||
|
||||
let selected = collect_mentions(&inputs, &skills, &disabled, &connector_counts);
|
||||
|
||||
@@ -3,22 +3,24 @@ use std::path::Path;
|
||||
|
||||
use crate::SkillLoadOutcome;
|
||||
use crate::SkillMetadata;
|
||||
use codex_exec_server::EnvironmentPathRef;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
|
||||
pub(crate) fn build_implicit_skill_path_indexes(
|
||||
skills: Vec<SkillMetadata>,
|
||||
) -> (
|
||||
HashMap<AbsolutePathBuf, SkillMetadata>,
|
||||
HashMap<AbsolutePathBuf, SkillMetadata>,
|
||||
HashMap<EnvironmentPathRef, SkillMetadata>,
|
||||
HashMap<EnvironmentPathRef, SkillMetadata>,
|
||||
) {
|
||||
let mut by_scripts_dir = HashMap::new();
|
||||
let mut by_skill_doc_path = HashMap::new();
|
||||
for skill in skills {
|
||||
let skill_doc_path = canonicalize_if_exists(&skill.path_to_skills_md);
|
||||
let skill_doc_path = canonicalize_if_exists(&skill.source_path);
|
||||
by_skill_doc_path.insert(skill_doc_path, skill.clone());
|
||||
|
||||
if let Some(skill_dir) = skill.path_to_skills_md.parent() {
|
||||
let scripts_dir = canonicalize_if_exists(&skill_dir.join("scripts"));
|
||||
let scripts_dir =
|
||||
canonicalize_if_exists(&skill.source_path.with_path(skill_dir.join("scripts")));
|
||||
by_scripts_dir.insert(scripts_dir, skill);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +31,7 @@ pub(crate) fn build_implicit_skill_path_indexes(
|
||||
pub fn detect_implicit_skill_invocation_for_command(
|
||||
outcome: &SkillLoadOutcome,
|
||||
command: &str,
|
||||
workdir: &AbsolutePathBuf,
|
||||
workdir: &EnvironmentPathRef,
|
||||
) -> Option<SkillMetadata> {
|
||||
let workdir = canonicalize_if_exists(workdir);
|
||||
let tokens = tokenize_command(command);
|
||||
@@ -81,14 +83,20 @@ fn script_run_token(tokens: &[String]) -> Option<&str> {
|
||||
fn detect_skill_script_run(
|
||||
outcome: &SkillLoadOutcome,
|
||||
tokens: &[String],
|
||||
workdir: &AbsolutePathBuf,
|
||||
workdir: &EnvironmentPathRef,
|
||||
) -> Option<SkillMetadata> {
|
||||
let script_token = script_run_token(tokens)?;
|
||||
let script_path = Path::new(script_token);
|
||||
let script_path = canonicalize_if_exists(&workdir.join(script_path));
|
||||
let script_path = canonicalize_if_exists(&resolve_path_ref(workdir, script_path)?);
|
||||
|
||||
for path in script_path.ancestors() {
|
||||
if let Some(candidate) = outcome.implicit_skills_by_scripts_dir.get(&path) {
|
||||
for path in script_path.path().ancestors() {
|
||||
let Ok(path) = AbsolutePathBuf::from_absolute_path(path) else {
|
||||
continue;
|
||||
};
|
||||
if let Some(candidate) = outcome
|
||||
.implicit_skills_by_scripts_dir
|
||||
.get(&script_path.with_path(path))
|
||||
{
|
||||
return Some(candidate.clone());
|
||||
}
|
||||
}
|
||||
@@ -99,7 +107,7 @@ fn detect_skill_script_run(
|
||||
fn detect_skill_doc_read(
|
||||
outcome: &SkillLoadOutcome,
|
||||
tokens: &[String],
|
||||
workdir: &AbsolutePathBuf,
|
||||
workdir: &EnvironmentPathRef,
|
||||
) -> Option<SkillMetadata> {
|
||||
if !command_reads_file(tokens) {
|
||||
return None;
|
||||
@@ -110,7 +118,7 @@ fn detect_skill_doc_read(
|
||||
continue;
|
||||
}
|
||||
let path = Path::new(token);
|
||||
let candidate_path = canonicalize_if_exists(&workdir.join(path));
|
||||
let candidate_path = canonicalize_if_exists(&resolve_path_ref(workdir, path)?);
|
||||
if let Some(candidate) = outcome.implicit_skills_by_doc_path.get(&candidate_path) {
|
||||
return Some(candidate.clone());
|
||||
}
|
||||
@@ -136,8 +144,24 @@ fn command_basename(command: &str) -> String {
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn canonicalize_if_exists(path: &AbsolutePathBuf) -> AbsolutePathBuf {
|
||||
path.canonicalize().unwrap_or_else(|_| path.clone())
|
||||
fn resolve_path_ref(workdir: &EnvironmentPathRef, path: &Path) -> Option<EnvironmentPathRef> {
|
||||
if path.is_absolute() {
|
||||
AbsolutePathBuf::from_absolute_path(path)
|
||||
.ok()
|
||||
.map(|path| workdir.with_path(path))
|
||||
} else {
|
||||
workdir.join_relative(path)
|
||||
}
|
||||
}
|
||||
|
||||
fn canonicalize_if_exists(path: &EnvironmentPathRef) -> EnvironmentPathRef {
|
||||
// TODO: Canonicalize through the bound executor filesystem once it exposes a realpath API.
|
||||
// The local fallback below cannot resolve remote-only paths.
|
||||
path.with_path(
|
||||
path.path()
|
||||
.canonicalize()
|
||||
.unwrap_or_else(|_| path.path().clone()),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -19,6 +19,7 @@ fn test_skill_metadata(skill_doc_path: AbsolutePathBuf) -> SkillMetadata {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local((skill_doc_path).clone()),
|
||||
path_to_skills_md: skill_doc_path,
|
||||
scope: codex_protocol::protocol::SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -29,6 +30,10 @@ fn test_path_display(unix_path: &str) -> String {
|
||||
test_path_buf(unix_path).display().to_string()
|
||||
}
|
||||
|
||||
fn local_path_ref(path: AbsolutePathBuf) -> codex_exec_server::EnvironmentPathRef {
|
||||
codex_exec_server::EnvironmentPathRef::local(path)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script_run_detection_matches_runner_plus_extension() {
|
||||
let tokens = vec![
|
||||
@@ -54,7 +59,7 @@ fn script_run_detection_excludes_python_c() {
|
||||
#[test]
|
||||
fn skill_doc_read_detection_matches_absolute_path() {
|
||||
let skill_doc_path = test_path_buf("/tmp/skill-test/SKILL.md").abs();
|
||||
let normalized_skill_doc_path = canonicalize_if_exists(&skill_doc_path);
|
||||
let normalized_skill_doc_path = canonicalize_if_exists(&local_path_ref(skill_doc_path.clone()));
|
||||
let skill = test_skill_metadata(skill_doc_path);
|
||||
let outcome = SkillLoadOutcome {
|
||||
implicit_skills_by_scripts_dir: Arc::new(HashMap::new()),
|
||||
@@ -68,7 +73,11 @@ fn skill_doc_read_detection_matches_absolute_path() {
|
||||
"|".to_string(),
|
||||
"head".to_string(),
|
||||
];
|
||||
let found = detect_skill_doc_read(&outcome, &tokens, &test_path_buf("/tmp").abs());
|
||||
let found = detect_skill_doc_read(
|
||||
&outcome,
|
||||
&tokens,
|
||||
&local_path_ref(test_path_buf("/tmp").abs()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
found.map(|value| value.name),
|
||||
@@ -79,7 +88,9 @@ fn skill_doc_read_detection_matches_absolute_path() {
|
||||
#[test]
|
||||
fn skill_script_run_detection_matches_relative_path_from_skill_root() {
|
||||
let skill_doc_path = test_path_buf("/tmp/skill-test/SKILL.md").abs();
|
||||
let scripts_dir = canonicalize_if_exists(&test_path_buf("/tmp/skill-test/scripts").abs());
|
||||
let scripts_dir = canonicalize_if_exists(&local_path_ref(
|
||||
test_path_buf("/tmp/skill-test/scripts").abs(),
|
||||
));
|
||||
let skill = test_skill_metadata(skill_doc_path);
|
||||
let outcome = SkillLoadOutcome {
|
||||
implicit_skills_by_scripts_dir: Arc::new(HashMap::from([(scripts_dir, skill)])),
|
||||
@@ -91,7 +102,11 @@ fn skill_script_run_detection_matches_relative_path_from_skill_root() {
|
||||
"scripts/fetch_comments.py".to_string(),
|
||||
];
|
||||
|
||||
let found = detect_skill_script_run(&outcome, &tokens, &test_path_buf("/tmp/skill-test").abs());
|
||||
let found = detect_skill_script_run(
|
||||
&outcome,
|
||||
&tokens,
|
||||
&local_path_ref(test_path_buf("/tmp/skill-test").abs()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
found.map(|value| value.name),
|
||||
@@ -102,7 +117,9 @@ fn skill_script_run_detection_matches_relative_path_from_skill_root() {
|
||||
#[test]
|
||||
fn skill_script_run_detection_matches_absolute_path_from_any_workdir() {
|
||||
let skill_doc_path = test_path_buf("/tmp/skill-test/SKILL.md").abs();
|
||||
let scripts_dir = canonicalize_if_exists(&test_path_buf("/tmp/skill-test/scripts").abs());
|
||||
let scripts_dir = canonicalize_if_exists(&local_path_ref(
|
||||
test_path_buf("/tmp/skill-test/scripts").abs(),
|
||||
));
|
||||
let skill = test_skill_metadata(skill_doc_path);
|
||||
let outcome = SkillLoadOutcome {
|
||||
implicit_skills_by_scripts_dir: Arc::new(HashMap::from([(scripts_dir, skill)])),
|
||||
@@ -114,7 +131,11 @@ fn skill_script_run_detection_matches_absolute_path_from_any_workdir() {
|
||||
test_path_display("/tmp/skill-test/scripts/fetch_comments.py"),
|
||||
];
|
||||
|
||||
let found = detect_skill_script_run(&outcome, &tokens, &test_path_buf("/tmp/other").abs());
|
||||
let found = detect_skill_script_run(
|
||||
&outcome,
|
||||
&tokens,
|
||||
&local_path_ref(test_path_buf("/tmp/other").abs()),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
found.map(|value| value.name),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::model::SkillDependencies;
|
||||
use crate::model::SkillError;
|
||||
use crate::model::SkillFileSystemsByPath;
|
||||
use crate::model::SkillInterface;
|
||||
use crate::model::SkillLoadOutcome;
|
||||
use crate::model::SkillMetadata;
|
||||
@@ -162,14 +161,11 @@ where
|
||||
I: IntoIterator<Item = SkillRoot>,
|
||||
{
|
||||
let mut outcome = SkillLoadOutcome::default();
|
||||
let mut skill_roots: Vec<AbsolutePathBuf> = Vec::new();
|
||||
let mut skill_root_by_path: HashMap<AbsolutePathBuf, AbsolutePathBuf> = HashMap::new();
|
||||
let mut file_systems_by_skill_path: HashMap<AbsolutePathBuf, Arc<dyn ExecutorFileSystem>> =
|
||||
HashMap::new();
|
||||
let mut skill_roots: Vec<EnvironmentPathRef> = Vec::new();
|
||||
let mut skill_root_by_path: HashMap<EnvironmentPathRef, EnvironmentPathRef> = HashMap::new();
|
||||
for root in roots {
|
||||
let root_path = canonicalize_for_skill_identity(root.path.path());
|
||||
let root_path_ref = root.path.with_path(root_path.clone());
|
||||
let fs = root_path_ref.file_system();
|
||||
let skills_before_root = outcome.skills.len();
|
||||
discover_skills_under_root(
|
||||
&root_path_ref,
|
||||
@@ -180,34 +176,29 @@ where
|
||||
)
|
||||
.await;
|
||||
for skill in &outcome.skills[skills_before_root..] {
|
||||
if !skill_roots.contains(&root_path) {
|
||||
skill_roots.push(root_path.clone());
|
||||
if !skill_roots.contains(&root_path_ref) {
|
||||
skill_roots.push(root_path_ref.clone());
|
||||
}
|
||||
skill_root_by_path
|
||||
.entry(skill.path_to_skills_md.clone())
|
||||
.or_insert_with(|| root_path.clone());
|
||||
file_systems_by_skill_path
|
||||
.entry(skill.path_to_skills_md.clone())
|
||||
.or_insert_with(|| Arc::clone(&fs));
|
||||
.entry(skill.source_path.clone())
|
||||
.or_insert_with(|| root_path_ref.clone());
|
||||
}
|
||||
}
|
||||
|
||||
let mut seen: HashSet<AbsolutePathBuf> = HashSet::new();
|
||||
let mut seen: HashSet<EnvironmentPathRef> = HashSet::new();
|
||||
outcome
|
||||
.skills
|
||||
.retain(|skill| seen.insert(skill.path_to_skills_md.clone()));
|
||||
let retained_skill_paths: HashSet<AbsolutePathBuf> = outcome
|
||||
.retain(|skill| seen.insert(skill.source_path.clone()));
|
||||
let retained_skill_paths: HashSet<EnvironmentPathRef> = outcome
|
||||
.skills
|
||||
.iter()
|
||||
.map(|skill| skill.path_to_skills_md.clone())
|
||||
.map(|skill| skill.source_path.clone())
|
||||
.collect();
|
||||
skill_root_by_path.retain(|path, _| retained_skill_paths.contains(path));
|
||||
let used_roots: HashSet<AbsolutePathBuf> = skill_root_by_path.values().cloned().collect();
|
||||
let used_roots: HashSet<EnvironmentPathRef> = skill_root_by_path.values().cloned().collect();
|
||||
skill_roots.retain(|root| used_roots.contains(root));
|
||||
file_systems_by_skill_path.retain(|path, _| retained_skill_paths.contains(path));
|
||||
outcome.skill_roots = skill_roots;
|
||||
outcome.skill_root_by_path = Arc::new(skill_root_by_path);
|
||||
outcome.file_systems_by_skill_path = SkillFileSystemsByPath::new(file_systems_by_skill_path);
|
||||
|
||||
fn scope_rank(scope: SkillScope) -> u8 {
|
||||
// Higher-priority scopes first (matches root scan order for dedupe).
|
||||
@@ -230,15 +221,14 @@ where
|
||||
}
|
||||
|
||||
pub(crate) async fn skill_roots(
|
||||
env_path: &EnvironmentPathRef,
|
||||
env_path: Option<&EnvironmentPathRef>,
|
||||
local_file_system: Option<&Arc<dyn ExecutorFileSystem>>,
|
||||
config_layer_stack: &ConfigLayerStack,
|
||||
plugin_skill_roots: Vec<PluginSkillRoot>,
|
||||
extra_skill_roots: Vec<AbsolutePathBuf>,
|
||||
) -> Vec<SkillRoot> {
|
||||
// `env_path` owns workspace/repo-relative skill discovery for the selected environment.
|
||||
// `local_file_system` owns client-local system/user/plugin roots and is absent when local exec
|
||||
// is disabled, in which case those local roots intentionally do not load.
|
||||
// `local_file_system` owns client-local system/user/plugin roots.
|
||||
let home_dir =
|
||||
home_dir().and_then(|path| AbsolutePathBuf::from_absolute_path_checked(path).ok());
|
||||
skill_roots_with_home_dir(
|
||||
@@ -253,7 +243,7 @@ pub(crate) async fn skill_roots(
|
||||
}
|
||||
|
||||
async fn skill_roots_with_home_dir(
|
||||
env_path: &EnvironmentPathRef,
|
||||
env_path: Option<&EnvironmentPathRef>,
|
||||
local_file_system: Option<&Arc<dyn ExecutorFileSystem>>,
|
||||
config_layer_stack: &ConfigLayerStack,
|
||||
home_dir: Option<&AbsolutePathBuf>,
|
||||
@@ -262,7 +252,10 @@ async fn skill_roots_with_home_dir(
|
||||
) -> Vec<SkillRoot> {
|
||||
// Assemble one precedence-ordered root list from the two authorities above, then dedupe before
|
||||
// any reads happen so downstream loading stays oblivious to local-vs-selected-env routing.
|
||||
let mut roots = repo_config_skill_roots(env_path, config_layer_stack);
|
||||
let mut roots = env_path
|
||||
.into_iter()
|
||||
.flat_map(|env_path| repo_config_skill_roots(env_path, config_layer_stack))
|
||||
.collect::<Vec<_>>();
|
||||
roots.extend(local_skill_roots(
|
||||
local_file_system,
|
||||
config_layer_stack,
|
||||
@@ -270,7 +263,9 @@ async fn skill_roots_with_home_dir(
|
||||
plugin_skill_roots,
|
||||
extra_skill_roots,
|
||||
));
|
||||
roots.extend(repo_agents_skill_roots(env_path, config_layer_stack).await);
|
||||
if let Some(env_path) = env_path {
|
||||
roots.extend(repo_agents_skill_roots(env_path, config_layer_stack).await);
|
||||
}
|
||||
dedupe_skill_roots_by_path(&mut roots);
|
||||
roots
|
||||
}
|
||||
@@ -283,11 +278,10 @@ fn local_skill_roots(
|
||||
extra_skill_roots: Vec<AbsolutePathBuf>,
|
||||
) -> Vec<SkillRoot> {
|
||||
// These roots are absolute paths on the client machine, not paths inside the selected
|
||||
// workspace environment. Bind them to the available local exec filesystem so remote turns
|
||||
// keep loading local installed/bundled/plugin skills without reading those paths remotely.
|
||||
// workspace environment. Bind them to the local-authority filesystem so remote turns keep
|
||||
// loading local installed/bundled/plugin skills without reading those paths remotely.
|
||||
let Some(local_file_system) = local_file_system else {
|
||||
// Local exec can be disabled. In that case, keep repo/env skill loading intact but skip
|
||||
// local absolute roots instead of falling back to the process-global local filesystem.
|
||||
// Some focused tests intentionally omit local authority to prove repo-only loading.
|
||||
return Vec::new();
|
||||
};
|
||||
let mut roots = Vec::new();
|
||||
@@ -524,6 +518,8 @@ fn dedupe_skill_roots_by_path(roots: &mut Vec<SkillRoot>) {
|
||||
}
|
||||
|
||||
fn canonicalize_for_skill_identity(path: &AbsolutePathBuf) -> AbsolutePathBuf {
|
||||
// TODO: Canonicalize through the bound executor filesystem once it exposes a realpath API.
|
||||
// The local fallback below cannot resolve remote-only paths.
|
||||
path.canonicalize().unwrap_or_else(|_| path.clone())
|
||||
}
|
||||
|
||||
@@ -742,7 +738,8 @@ async fn parse_skill_file(
|
||||
interface,
|
||||
dependencies,
|
||||
policy,
|
||||
path_to_skills_md: resolved_path,
|
||||
path_to_skills_md: resolved_path.clone(),
|
||||
source_path: skill_path.with_path(resolved_path),
|
||||
scope,
|
||||
plugin_id: plugin_id.map(str::to_string),
|
||||
})
|
||||
@@ -1135,7 +1132,7 @@ pub(crate) async fn skill_roots_from_layer_stack(
|
||||
let path_ref = EnvironmentPathRef::new(fs, cwd.clone());
|
||||
let local_file_system = path_ref.file_system();
|
||||
skill_roots_with_home_dir(
|
||||
&path_ref,
|
||||
Some(&path_ref),
|
||||
Some(&local_file_system),
|
||||
config_layer_stack,
|
||||
home_dir,
|
||||
|
||||
@@ -305,7 +305,7 @@ async fn skill_roots_bind_repo_and_local_roots_to_their_own_file_systems() -> an
|
||||
let local_file_system: Arc<dyn ExecutorFileSystem> = Arc::new(LocalFileSystem::unsandboxed());
|
||||
let env_path = EnvironmentPathRef::new(env_file_system.clone(), cfg.cwd.clone());
|
||||
let roots = super::skill_roots(
|
||||
&env_path,
|
||||
Some(&env_path),
|
||||
Some(&local_file_system),
|
||||
&cfg.config_layer_stack,
|
||||
Vec::new(),
|
||||
@@ -328,7 +328,7 @@ async fn skill_roots_bind_repo_and_local_roots_to_their_own_file_systems() -> an
|
||||
));
|
||||
|
||||
let roots_without_local = super::skill_roots(
|
||||
&env_path,
|
||||
Some(&env_path),
|
||||
/*local_file_system*/ None,
|
||||
&cfg.config_layer_stack,
|
||||
Vec::new(),
|
||||
@@ -396,6 +396,7 @@ async fn loads_skills_from_home_agents_dir_for_user_scope() -> anyhow::Result<()
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -534,6 +535,7 @@ async fn loads_skill_dependencies_metadata_from_yaml() {
|
||||
],
|
||||
}),
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -590,6 +592,9 @@ interface:
|
||||
}),
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(
|
||||
skill_path.as_path()
|
||||
)),
|
||||
path_to_skills_md: normalized(skill_path.as_path()),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -744,6 +749,7 @@ async fn accepts_icon_paths_under_assets_dir() {
|
||||
}),
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -785,6 +791,7 @@ async fn ignores_invalid_brand_color() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -839,6 +846,7 @@ async fn ignores_default_prompt_over_max_length() {
|
||||
}),
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -881,6 +889,7 @@ async fn drops_interface_when_icons_are_invalid() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -941,6 +950,7 @@ interface:
|
||||
}),
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: Some("twilio-developer-kit@test".to_string()),
|
||||
@@ -989,6 +999,7 @@ interface:
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: Some("twilio-developer-kit@test".to_string()),
|
||||
@@ -1034,6 +1045,9 @@ async fn loads_skills_via_symlinked_subdir_for_user_scope() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(
|
||||
&shared_skill_path
|
||||
)),
|
||||
path_to_skills_md: normalized(&shared_skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -1094,6 +1108,7 @@ async fn does_not_loop_on_symlink_cycle_for_user_scope() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -1130,6 +1145,9 @@ async fn loads_skills_via_symlinked_subdir_for_admin_scope() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(
|
||||
&shared_skill_path
|
||||
)),
|
||||
path_to_skills_md: normalized(&shared_skill_path),
|
||||
scope: SkillScope::Admin,
|
||||
plugin_id: None,
|
||||
@@ -1170,6 +1188,9 @@ async fn loads_skills_via_symlinked_subdir_for_repo_scope() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(
|
||||
&linked_skill_path
|
||||
)),
|
||||
path_to_skills_md: normalized(&linked_skill_path),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1234,6 +1255,9 @@ async fn respects_max_scan_depth_for_user_scope() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(
|
||||
&within_depth_path
|
||||
)),
|
||||
path_to_skills_md: normalized(&within_depth_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -1262,6 +1286,7 @@ async fn loads_valid_skill() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -1295,6 +1320,7 @@ async fn falls_back_to_directory_name_when_skill_name_is_missing() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -1340,6 +1366,7 @@ async fn namespaces_plugin_skills_using_plugin_name() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: Some("sample@test".to_string()),
|
||||
@@ -1372,6 +1399,7 @@ async fn loads_short_description_from_metadata() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -1485,6 +1513,7 @@ async fn loads_skills_from_repo_root() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1521,6 +1550,7 @@ async fn loads_skills_from_agents_dir_without_codex_dir() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1575,6 +1605,9 @@ async fn loads_skills_from_all_codex_dirs_under_project_root() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(
|
||||
&nested_skill_path
|
||||
)),
|
||||
path_to_skills_md: normalized(&nested_skill_path),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1586,6 +1619,9 @@ async fn loads_skills_from_all_codex_dirs_under_project_root() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(
|
||||
&root_skill_path
|
||||
)),
|
||||
path_to_skills_md: normalized(&root_skill_path),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1626,6 +1662,7 @@ async fn loads_skills_from_codex_dir_when_not_git_repo() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1669,6 +1706,7 @@ async fn deduplicates_by_path_preferring_first_root() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1676,6 +1714,41 @@ async fn deduplicates_by_path_preferring_first_root() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn preserves_same_absolute_skill_path_from_distinct_file_systems() {
|
||||
let root = tempfile::tempdir().expect("tempdir");
|
||||
let skill_path = write_skill_at(root.path(), "dupe", "dupe-skill", "from repo");
|
||||
let shared_path = root.path().abs();
|
||||
let first_file_system: Arc<dyn ExecutorFileSystem> = Arc::new(LocalFileSystem::unsandboxed());
|
||||
let second_file_system: Arc<dyn ExecutorFileSystem> = Arc::new(LocalFileSystem::unsandboxed());
|
||||
|
||||
let outcome = load_skills_from_roots([
|
||||
SkillRoot {
|
||||
path: EnvironmentPathRef::new(first_file_system, shared_path.clone()),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
plugin_root: None,
|
||||
},
|
||||
SkillRoot {
|
||||
path: EnvironmentPathRef::new(second_file_system, shared_path),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
plugin_root: None,
|
||||
},
|
||||
])
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
outcome
|
||||
.skills
|
||||
.iter()
|
||||
.map(|skill| skill.path_to_skills_md.clone())
|
||||
.collect::<Vec<_>>(),
|
||||
vec![normalized(&skill_path), normalized(&skill_path)]
|
||||
);
|
||||
assert_ne!(outcome.skills[0].source_path, outcome.skills[1].source_path);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn keeps_duplicate_names_from_repo_and_user() {
|
||||
let codex_home = tempfile::tempdir().expect("tempdir");
|
||||
@@ -1711,6 +1784,9 @@ async fn keeps_duplicate_names_from_repo_and_user() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(
|
||||
&repo_skill_path
|
||||
)),
|
||||
path_to_skills_md: normalized(&repo_skill_path),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1722,6 +1798,9 @@ async fn keeps_duplicate_names_from_repo_and_user() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(
|
||||
&user_skill_path
|
||||
)),
|
||||
path_to_skills_md: normalized(&user_skill_path),
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
@@ -1785,6 +1864,7 @@ async fn keeps_duplicate_names_from_nested_codex_dirs() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local((first_path).clone()),
|
||||
path_to_skills_md: first_path,
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1796,6 +1876,7 @@ async fn keeps_duplicate_names_from_nested_codex_dirs() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local((second_path).clone()),
|
||||
path_to_skills_md: second_path,
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1868,6 +1949,7 @@ async fn loads_skills_when_cwd_is_file_in_repo() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -1927,6 +2009,7 @@ async fn loads_skills_from_system_cache_when_present() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)),
|
||||
path_to_skills_md: normalized(&skill_path),
|
||||
scope: SkillScope::System,
|
||||
plugin_id: None,
|
||||
@@ -1942,7 +2025,7 @@ async fn skill_roots_include_admin_with_lowest_priority() {
|
||||
let cwd = local_env_path(cfg.cwd.clone());
|
||||
let local_file_system = cwd.file_system();
|
||||
let scopes: Vec<SkillScope> = super::skill_roots(
|
||||
&cwd,
|
||||
Some(&cwd),
|
||||
Some(&local_file_system),
|
||||
&cfg.config_layer_stack,
|
||||
Vec::new(),
|
||||
|
||||
@@ -27,7 +27,7 @@ use codex_exec_server::ExecutorFileSystem;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SkillsLoadInput {
|
||||
pub env_path: EnvironmentPathRef,
|
||||
pub env_path: Option<EnvironmentPathRef>,
|
||||
/// Local user/system/plugin skill roots are read from this filesystem for now.
|
||||
pub local_file_system: Option<Arc<dyn ExecutorFileSystem>>,
|
||||
pub effective_skill_roots: Vec<PluginSkillRoot>,
|
||||
@@ -49,7 +49,7 @@ impl std::fmt::Debug for SkillsLoadInput {
|
||||
|
||||
impl SkillsLoadInput {
|
||||
pub fn new(
|
||||
env_path: EnvironmentPathRef,
|
||||
env_path: Option<EnvironmentPathRef>,
|
||||
local_file_system: Option<Arc<dyn ExecutorFileSystem>>,
|
||||
effective_skill_roots: Vec<PluginSkillRoot>,
|
||||
config_layer_stack: ConfigLayerStack,
|
||||
@@ -136,7 +136,7 @@ impl SkillsManager {
|
||||
|
||||
pub async fn skill_roots_for_config(&self, input: &SkillsLoadInput) -> Vec<SkillRoot> {
|
||||
let mut roots = skill_roots(
|
||||
&input.env_path,
|
||||
input.env_path.as_ref(),
|
||||
input.local_file_system.as_ref(),
|
||||
&input.config_layer_stack,
|
||||
input.effective_skill_roots.clone(),
|
||||
@@ -168,7 +168,7 @@ impl SkillsManager {
|
||||
}
|
||||
|
||||
let mut roots = skill_roots(
|
||||
&input.env_path,
|
||||
input.env_path.as_ref(),
|
||||
input.local_file_system.as_ref(),
|
||||
&input.config_layer_stack,
|
||||
input.effective_skill_roots.clone(),
|
||||
@@ -254,7 +254,7 @@ impl SkillsManager {
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
struct SkillsPathCacheKey {
|
||||
env_path: EnvironmentPathRef,
|
||||
env_path: Option<EnvironmentPathRef>,
|
||||
local_file_system: Option<ExecutorFileSystemRef>,
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ fn config_skills_cache_key(
|
||||
|
||||
fn finalize_skill_outcome(
|
||||
mut outcome: SkillLoadOutcome,
|
||||
disabled_paths: HashSet<AbsolutePathBuf>,
|
||||
disabled_paths: HashSet<EnvironmentPathRef>,
|
||||
) -> SkillLoadOutcome {
|
||||
outcome.disabled_paths = disabled_paths;
|
||||
let (by_scripts_dir, by_doc_path) =
|
||||
|
||||
@@ -71,6 +71,10 @@ fn plugin_skill_root_for_skill_path(skill_path: &Path, plugin_id: &str) -> Plugi
|
||||
}
|
||||
|
||||
fn test_skill(name: &str, path: PathBuf) -> SkillMetadata {
|
||||
let path = path
|
||||
.abs()
|
||||
.canonicalize()
|
||||
.expect("skill path should canonicalize");
|
||||
SkillMetadata {
|
||||
name: name.to_string(),
|
||||
description: "test".to_string(),
|
||||
@@ -78,10 +82,8 @@ fn test_skill(name: &str, path: PathBuf) -> SkillMetadata {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: path
|
||||
.abs()
|
||||
.canonicalize()
|
||||
.expect("skill path should canonicalize"),
|
||||
source_path: EnvironmentPathRef::local(path.clone()),
|
||||
path_to_skills_md: path,
|
||||
scope: SkillScope::User,
|
||||
plugin_id: None,
|
||||
}
|
||||
@@ -98,7 +100,7 @@ fn local_skills_input(
|
||||
) -> SkillsLoadInput {
|
||||
let path_ref = skill_root_path_ref(cwd);
|
||||
SkillsLoadInput::new(
|
||||
path_ref,
|
||||
Some(path_ref),
|
||||
Some(Arc::clone(&LOCAL_FS)),
|
||||
effective_skill_roots,
|
||||
config_layer_stack.clone(),
|
||||
@@ -381,7 +383,7 @@ async fn skills_for_config_disables_plugin_skills_by_name() {
|
||||
.abs();
|
||||
|
||||
assert_eq!(skill.path_to_skills_md, skill_path);
|
||||
assert!(outcome.disabled_paths.contains(&skill.path_to_skills_md));
|
||||
assert!(outcome.disabled_paths.contains(&skill.source_path));
|
||||
assert!(
|
||||
!outcome
|
||||
.allowed_skills_for_implicit_invocation()
|
||||
@@ -475,7 +477,7 @@ async fn skills_for_cwd_without_local_fs_skips_local_roots() {
|
||||
)
|
||||
.expect("valid config layer stack");
|
||||
let skills_input = SkillsLoadInput::new(
|
||||
skill_root_path_ref(cwd.path().abs()),
|
||||
Some(skill_root_path_ref(cwd.path().abs())),
|
||||
/*local_file_system*/ None,
|
||||
Vec::new(),
|
||||
config_layer_stack.clone(),
|
||||
@@ -504,6 +506,66 @@ async fn skills_for_cwd_without_local_fs_skips_local_roots() {
|
||||
assert!(loaded_names.contains("repo-skill"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn skills_for_cwd_without_env_path_still_loads_local_roots() {
|
||||
let codex_home = tempfile::tempdir().expect("tempdir");
|
||||
let cwd = tempfile::tempdir().expect("tempdir");
|
||||
let repo_dot_codex = cwd.path().join(".codex");
|
||||
fs::create_dir_all(&repo_dot_codex).expect("create repo config dir");
|
||||
|
||||
write_user_skill(&codex_home, "user", "user-skill", "from local user root");
|
||||
let repo_skill_dir = repo_dot_codex.join("skills/repo");
|
||||
fs::create_dir_all(&repo_skill_dir).expect("create repo skill dir");
|
||||
fs::write(
|
||||
repo_skill_dir.join("SKILL.md"),
|
||||
"---\nname: repo-skill\ndescription: from repo root\n---\n\n# Body\n",
|
||||
)
|
||||
.expect("write repo skill");
|
||||
|
||||
let config_layer_stack = ConfigLayerStack::new(
|
||||
vec![
|
||||
user_config_layer(&codex_home, ""),
|
||||
ConfigLayerEntry::new(
|
||||
ConfigLayerSource::Project {
|
||||
dot_codex_folder: repo_dot_codex.abs(),
|
||||
},
|
||||
toml::Value::Table(toml::map::Map::new()),
|
||||
),
|
||||
],
|
||||
Default::default(),
|
||||
ConfigRequirementsToml::default(),
|
||||
)
|
||||
.expect("valid config layer stack");
|
||||
let skills_input = SkillsLoadInput::new(
|
||||
/*env_path*/ None,
|
||||
Some(Arc::clone(&LOCAL_FS)),
|
||||
Vec::new(),
|
||||
config_layer_stack.clone(),
|
||||
bundled_skills_enabled_from_stack(&config_layer_stack),
|
||||
);
|
||||
let skills_manager = SkillsManager::new(
|
||||
codex_home.path().abs(),
|
||||
/*bundled_skills_enabled*/ true,
|
||||
);
|
||||
|
||||
let outcome = skills_manager
|
||||
.skills_for_cwd(&skills_input, /*force_reload*/ true)
|
||||
.await;
|
||||
|
||||
assert!(
|
||||
outcome.errors.is_empty(),
|
||||
"unexpected errors: {:?}",
|
||||
outcome.errors
|
||||
);
|
||||
let loaded_names = outcome
|
||||
.skills
|
||||
.iter()
|
||||
.map(|skill| skill.name.as_str())
|
||||
.collect::<HashSet<_>>();
|
||||
assert!(loaded_names.contains("user-skill"));
|
||||
assert!(!loaded_names.contains("repo-skill"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn skills_for_config_excludes_bundled_skills_when_disabled_in_config() {
|
||||
let codex_home = tempfile::tempdir().expect("tempdir");
|
||||
@@ -656,10 +718,12 @@ fn disabled_paths_for_skills_allows_session_flags_to_disable_user_enabled_skill(
|
||||
let skill_config_rules = skill_config_rules_from_stack(&stack);
|
||||
assert_eq!(
|
||||
resolve_disabled_skill_paths(&[skill], &skill_config_rules),
|
||||
HashSet::from([skill_path
|
||||
.abs()
|
||||
.canonicalize()
|
||||
.expect("skill path should canonicalize")])
|
||||
HashSet::from([EnvironmentPathRef::local(
|
||||
skill_path
|
||||
.abs()
|
||||
.canonicalize()
|
||||
.expect("skill path should canonicalize"),
|
||||
)])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -689,10 +753,12 @@ fn disabled_paths_for_skills_disables_matching_name_selectors() {
|
||||
let skill_config_rules = skill_config_rules_from_stack(&stack);
|
||||
assert_eq!(
|
||||
resolve_disabled_skill_paths(&[skill], &skill_config_rules),
|
||||
HashSet::from([skill_path
|
||||
.abs()
|
||||
.canonicalize()
|
||||
.expect("skill path should canonicalize")])
|
||||
HashSet::from([EnvironmentPathRef::local(
|
||||
skill_path
|
||||
.abs()
|
||||
.canonicalize()
|
||||
.expect("skill path should canonicalize"),
|
||||
)])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -731,6 +797,44 @@ fn disabled_paths_for_skills_allows_name_selector_to_override_path_selector() {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, ignore)]
|
||||
#[test]
|
||||
fn disabled_paths_for_skills_disables_same_raw_path_in_each_file_system() {
|
||||
let tempdir = tempfile::tempdir().expect("tempdir");
|
||||
let skill_path = write_demo_skill(&tempdir);
|
||||
let mut second_skill = test_skill("demo-skill", skill_path.clone());
|
||||
second_skill.source_path = EnvironmentPathRef::new(
|
||||
Arc::new(codex_exec_server::LocalFileSystem::unsandboxed()),
|
||||
second_skill.path_to_skills_md.clone(),
|
||||
);
|
||||
let local_skill = test_skill("demo-skill", skill_path.clone());
|
||||
let user_file = AbsolutePathBuf::try_from(tempdir.path().join("config.toml"))
|
||||
.expect("user config path should be absolute");
|
||||
let user_layer = ConfigLayerEntry::new(
|
||||
ConfigLayerSource::User {
|
||||
file: user_file,
|
||||
profile: None,
|
||||
},
|
||||
toml::from_str(&path_toggle_config(&skill_path, /*enabled*/ false))
|
||||
.expect("user layer toml"),
|
||||
);
|
||||
let stack = ConfigLayerStack::new(
|
||||
vec![user_layer],
|
||||
Default::default(),
|
||||
ConfigRequirementsToml::default(),
|
||||
)
|
||||
.expect("valid config layer stack");
|
||||
|
||||
let skill_config_rules = skill_config_rules_from_stack(&stack);
|
||||
assert_eq!(
|
||||
resolve_disabled_skill_paths(
|
||||
&[second_skill.clone(), local_skill.clone()],
|
||||
&skill_config_rules
|
||||
),
|
||||
HashSet::from([second_skill.source_path, local_skill.source_path])
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg_attr(windows, ignore)]
|
||||
#[tokio::test]
|
||||
async fn skills_for_config_ignores_cwd_cache_when_session_flags_reenable_skill() {
|
||||
|
||||
@@ -2,17 +2,17 @@ use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::SkillMetadata;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_exec_server::EnvironmentPathRef;
|
||||
|
||||
/// Counts how often each skill name appears (exact and ASCII-lowercase), excluding disabled paths.
|
||||
pub fn build_skill_name_counts(
|
||||
skills: &[SkillMetadata],
|
||||
disabled_paths: &HashSet<AbsolutePathBuf>,
|
||||
disabled_paths: &HashSet<EnvironmentPathRef>,
|
||||
) -> (HashMap<String, usize>, HashMap<String, usize>) {
|
||||
let mut exact_counts: HashMap<String, usize> = HashMap::new();
|
||||
let mut lower_counts: HashMap<String, usize> = HashMap::new();
|
||||
for skill in skills {
|
||||
if disabled_paths.contains(&skill.path_to_skills_md) {
|
||||
if disabled_paths.contains(&skill.source_path) {
|
||||
continue;
|
||||
}
|
||||
*exact_counts.entry(skill.name.clone()).or_insert(0) += 1;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use codex_exec_server::ExecutorFileSystem;
|
||||
use codex_exec_server::EnvironmentPathRef;
|
||||
use codex_protocol::protocol::Product;
|
||||
use codex_protocol::protocol::SkillScope;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -17,6 +16,8 @@ pub struct SkillMetadata {
|
||||
pub policy: Option<SkillPolicy>,
|
||||
/// Path to the SKILLS.md file that declares this skill.
|
||||
pub path_to_skills_md: AbsolutePathBuf,
|
||||
/// Bound path to the SKILL.md file that declares this skill.
|
||||
pub source_path: EnvironmentPathRef,
|
||||
pub scope: SkillScope,
|
||||
pub plugin_id: Option<String>,
|
||||
}
|
||||
@@ -88,17 +89,16 @@ pub struct SkillError {
|
||||
pub struct SkillLoadOutcome {
|
||||
pub skills: Vec<SkillMetadata>,
|
||||
pub errors: Vec<SkillError>,
|
||||
pub disabled_paths: HashSet<AbsolutePathBuf>,
|
||||
pub(crate) skill_roots: Vec<AbsolutePathBuf>,
|
||||
pub(crate) skill_root_by_path: Arc<HashMap<AbsolutePathBuf, AbsolutePathBuf>>,
|
||||
pub(crate) file_systems_by_skill_path: SkillFileSystemsByPath,
|
||||
pub(crate) implicit_skills_by_scripts_dir: Arc<HashMap<AbsolutePathBuf, SkillMetadata>>,
|
||||
pub(crate) implicit_skills_by_doc_path: Arc<HashMap<AbsolutePathBuf, SkillMetadata>>,
|
||||
pub disabled_paths: HashSet<EnvironmentPathRef>,
|
||||
pub(crate) skill_roots: Vec<EnvironmentPathRef>,
|
||||
pub(crate) skill_root_by_path: Arc<HashMap<EnvironmentPathRef, EnvironmentPathRef>>,
|
||||
pub(crate) implicit_skills_by_scripts_dir: Arc<HashMap<EnvironmentPathRef, SkillMetadata>>,
|
||||
pub(crate) implicit_skills_by_doc_path: Arc<HashMap<EnvironmentPathRef, SkillMetadata>>,
|
||||
}
|
||||
|
||||
impl SkillLoadOutcome {
|
||||
pub fn is_skill_enabled(&self, skill: &SkillMetadata) -> bool {
|
||||
!self.disabled_paths.contains(&skill.path_to_skills_md)
|
||||
!self.disabled_paths.contains(&skill.source_path)
|
||||
}
|
||||
|
||||
pub fn is_skill_allowed_for_implicit_invocation(&self, skill: &SkillMetadata) -> bool {
|
||||
@@ -118,49 +118,6 @@ impl SkillLoadOutcome {
|
||||
.iter()
|
||||
.map(|skill| (skill, self.is_skill_enabled(skill)))
|
||||
}
|
||||
|
||||
pub(crate) fn file_system_for_skill(
|
||||
&self,
|
||||
skill: &SkillMetadata,
|
||||
) -> Option<Arc<dyn ExecutorFileSystem>> {
|
||||
self.file_systems_by_skill_path
|
||||
.get(&skill.path_to_skills_md)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub(crate) struct SkillFileSystemsByPath {
|
||||
values: Arc<HashMap<AbsolutePathBuf, Arc<dyn ExecutorFileSystem>>>,
|
||||
}
|
||||
|
||||
impl SkillFileSystemsByPath {
|
||||
pub(crate) fn new(values: HashMap<AbsolutePathBuf, Arc<dyn ExecutorFileSystem>>) -> Self {
|
||||
Self {
|
||||
values: Arc::new(values),
|
||||
}
|
||||
}
|
||||
|
||||
fn get(&self, path: &AbsolutePathBuf) -> Option<Arc<dyn ExecutorFileSystem>> {
|
||||
self.values.get(path).map(Arc::clone)
|
||||
}
|
||||
|
||||
fn retain_paths(&mut self, paths: &HashSet<AbsolutePathBuf>) {
|
||||
self.values = Arc::new(
|
||||
self.values
|
||||
.iter()
|
||||
.filter(|(path, _)| paths.contains(*path))
|
||||
.map(|(path, fs)| (path.clone(), Arc::clone(fs)))
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for SkillFileSystemsByPath {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("SkillFileSystemsByPath")
|
||||
.field("len", &self.values.len())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filter_skill_load_outcome_for_product(
|
||||
@@ -170,14 +127,11 @@ pub fn filter_skill_load_outcome_for_product(
|
||||
outcome
|
||||
.skills
|
||||
.retain(|skill| skill.matches_product_restriction_for_product(restriction_product));
|
||||
let retained_paths: HashSet<AbsolutePathBuf> = outcome
|
||||
let retained_paths: HashSet<EnvironmentPathRef> = outcome
|
||||
.skills
|
||||
.iter()
|
||||
.map(|skill| skill.path_to_skills_md.clone())
|
||||
.map(|skill| skill.source_path.clone())
|
||||
.collect();
|
||||
outcome
|
||||
.file_systems_by_skill_path
|
||||
.retain_paths(&retained_paths);
|
||||
outcome.skill_root_by_path = Arc::new(
|
||||
outcome
|
||||
.skill_root_by_path
|
||||
@@ -186,7 +140,7 @@ pub fn filter_skill_load_outcome_for_product(
|
||||
.map(|(path, root)| (path.clone(), root.clone()))
|
||||
.collect(),
|
||||
);
|
||||
let retained_roots: HashSet<AbsolutePathBuf> =
|
||||
let retained_roots: HashSet<EnvironmentPathRef> =
|
||||
outcome.skill_root_by_path.values().cloned().collect();
|
||||
outcome
|
||||
.skill_roots
|
||||
|
||||
@@ -5,6 +5,7 @@ use std::path::Path;
|
||||
|
||||
use crate::model::SkillLoadOutcome;
|
||||
use crate::model::SkillMetadata;
|
||||
use codex_exec_server::EnvironmentPathRef;
|
||||
use codex_otel::SessionTelemetry;
|
||||
use codex_otel::THREAD_SKILLS_DESCRIPTION_TRUNCATED_CHARS_METRIC;
|
||||
use codex_otel::THREAD_SKILLS_ENABLED_TOTAL_METRIC;
|
||||
@@ -665,8 +666,8 @@ struct SkillPathAliases {
|
||||
|
||||
struct AliasPlan {
|
||||
aliases: SkillPathAliases,
|
||||
root_aliases: HashMap<AbsolutePathBuf, String>,
|
||||
alias_root_by_path: HashMap<AbsolutePathBuf, AbsolutePathBuf>,
|
||||
root_aliases: HashMap<EnvironmentPathRef, String>,
|
||||
alias_root_by_path: HashMap<EnvironmentPathRef, EnvironmentPathRef>,
|
||||
table_cost: usize,
|
||||
}
|
||||
|
||||
@@ -677,7 +678,7 @@ fn build_alias_plan(
|
||||
) -> Option<AliasPlan> {
|
||||
let skill_paths = skills
|
||||
.iter()
|
||||
.map(|skill| skill.path_to_skills_md.clone())
|
||||
.map(|skill| skill.source_path.clone())
|
||||
.collect::<HashSet<_>>();
|
||||
let skill_root_by_path = outcome
|
||||
.skill_root_by_path
|
||||
@@ -736,9 +737,9 @@ fn build_alias_plan(
|
||||
}
|
||||
|
||||
fn ordered_alias_roots(
|
||||
used_roots: &[AbsolutePathBuf],
|
||||
alias_root_by_skill_root: &HashMap<AbsolutePathBuf, AbsolutePathBuf>,
|
||||
) -> Option<Vec<AbsolutePathBuf>> {
|
||||
used_roots: &[EnvironmentPathRef],
|
||||
alias_root_by_skill_root: &HashMap<EnvironmentPathRef, EnvironmentPathRef>,
|
||||
) -> Option<Vec<EnvironmentPathRef>> {
|
||||
let mut seen = HashSet::new();
|
||||
let mut alias_roots = Vec::new();
|
||||
for root in used_roots {
|
||||
@@ -751,10 +752,10 @@ fn ordered_alias_roots(
|
||||
}
|
||||
|
||||
fn alias_root_for_skill_root(
|
||||
root: &AbsolutePathBuf,
|
||||
root: &EnvironmentPathRef,
|
||||
plugin_version_skill_counts: &HashMap<AbsolutePathBuf, usize>,
|
||||
) -> AbsolutePathBuf {
|
||||
let Some(plugin_version_base) = plugin_version_base(root.as_path()) else {
|
||||
) -> EnvironmentPathRef {
|
||||
let Some(plugin_version_base) = plugin_version_base(root.path().as_path()) else {
|
||||
return root.clone();
|
||||
};
|
||||
let skill_count = plugin_version_skill_counts
|
||||
@@ -764,16 +765,18 @@ fn alias_root_for_skill_root(
|
||||
if skill_count > 1 {
|
||||
root.clone()
|
||||
} else {
|
||||
plugin_marketplace_base(root.as_path()).unwrap_or_else(|| root.clone())
|
||||
plugin_marketplace_base(root.path().as_path())
|
||||
.map(|path| root.with_path(path))
|
||||
.unwrap_or_else(|| root.clone())
|
||||
}
|
||||
}
|
||||
|
||||
fn plugin_version_skill_counts_for_skill_roots<'a>(
|
||||
skill_roots: impl Iterator<Item = &'a AbsolutePathBuf>,
|
||||
skill_roots: impl Iterator<Item = &'a EnvironmentPathRef>,
|
||||
) -> HashMap<AbsolutePathBuf, usize> {
|
||||
let mut counts = HashMap::new();
|
||||
for root in skill_roots {
|
||||
if let Some(plugin_version_base) = plugin_version_base(root.as_path()) {
|
||||
if let Some(plugin_version_base) = plugin_version_base(root.path().as_path()) {
|
||||
let count = counts.entry(plugin_version_base).or_insert(0usize);
|
||||
*count = count.saturating_add(1);
|
||||
}
|
||||
@@ -793,12 +796,12 @@ fn aliased_metadata_overhead_cost(
|
||||
.saturating_sub(budget.cost(&absolute_body))
|
||||
}
|
||||
|
||||
fn build_skill_root_lines(roots: &[AbsolutePathBuf]) -> Vec<String> {
|
||||
fn build_skill_root_lines(roots: &[EnvironmentPathRef]) -> Vec<String> {
|
||||
roots
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, root)| {
|
||||
let root_str = root.to_string_lossy().replace('\\', "/");
|
||||
let root_str = root.path().to_string_lossy().replace('\\', "/");
|
||||
format!("- `r{index}` = `{root_str}`")
|
||||
})
|
||||
.collect()
|
||||
@@ -840,12 +843,12 @@ fn render_skill_path_with_aliases(skill: &SkillMetadata, plan: &AliasPlan) -> St
|
||||
}
|
||||
|
||||
fn outcome_relative_skill_path(skill: &SkillMetadata, plan: &AliasPlan) -> Option<String> {
|
||||
let alias_root = plan.alias_root_by_path.get(&skill.path_to_skills_md)?;
|
||||
let alias_root = plan.alias_root_by_path.get(&skill.source_path)?;
|
||||
let alias = plan.root_aliases.get(alias_root)?;
|
||||
let relative_path = skill
|
||||
.path_to_skills_md
|
||||
.as_path()
|
||||
.strip_prefix(alias_root.as_path())
|
||||
.strip_prefix(alias_root.path().as_path())
|
||||
.ok()?;
|
||||
let relative_path = relative_path.to_string_lossy().replace('\\', "/");
|
||||
Some(format!("{alias}/{relative_path}"))
|
||||
@@ -920,6 +923,9 @@ mod tests {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf(&format!("/tmp/{name}/SKILL.md")).abs(),
|
||||
),
|
||||
path_to_skills_md: test_path_buf(&format!("/tmp/{name}/SKILL.md")).abs(),
|
||||
scope,
|
||||
plugin_id: None,
|
||||
@@ -948,6 +954,10 @@ mod tests {
|
||||
skills: Vec<SkillMetadata>,
|
||||
roots: Vec<AbsolutePathBuf>,
|
||||
) -> SkillLoadOutcome {
|
||||
let roots = roots
|
||||
.into_iter()
|
||||
.map(codex_exec_server::EnvironmentPathRef::local)
|
||||
.collect::<Vec<_>>();
|
||||
let skill_root_by_path = skills
|
||||
.iter()
|
||||
.filter_map(|skill| {
|
||||
@@ -957,9 +967,9 @@ mod tests {
|
||||
skill
|
||||
.path_to_skills_md
|
||||
.as_path()
|
||||
.starts_with(root.as_path())
|
||||
.starts_with(root.path().as_path())
|
||||
})
|
||||
.map(|root| (skill.path_to_skills_md.clone(), root.clone()))
|
||||
.map(|root| (skill.source_path.clone(), root.clone()))
|
||||
})
|
||||
.collect::<HashMap<_, _>>();
|
||||
SkillLoadOutcome {
|
||||
@@ -1507,6 +1517,7 @@ mod tests {
|
||||
fn skill_with_path(name: &str, path: &AbsolutePathBuf) -> SkillMetadata {
|
||||
let mut skill = make_skill(name, SkillScope::User);
|
||||
skill.path_to_skills_md = path.clone();
|
||||
skill.source_path = codex_exec_server::EnvironmentPathRef::local(path.clone());
|
||||
skill
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,7 +427,7 @@ enabled = false
|
||||
);
|
||||
let skills_input = skills_load_input_from_config(
|
||||
&config,
|
||||
cwd,
|
||||
Some(cwd),
|
||||
Some(Arc::clone(&codex_exec_server::LOCAL_FS)),
|
||||
effective_skill_roots,
|
||||
);
|
||||
|
||||
@@ -461,12 +461,7 @@ async fn warm_plugins_and_skills_for_session_init(
|
||||
environment.cwd.clone(),
|
||||
)
|
||||
});
|
||||
let Some(path_ref) = path_ref else {
|
||||
return Vec::new();
|
||||
};
|
||||
let local_file_system = environment_manager
|
||||
.try_local_environment()
|
||||
.map(|environment| environment.get_filesystem());
|
||||
let local_file_system = Some(Arc::clone(&codex_exec_server::LOCAL_FS));
|
||||
let plugins_input = config.plugins_config_input();
|
||||
let plugin_outcome = plugins_manager.plugins_for_config(&plugins_input).await;
|
||||
let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots();
|
||||
|
||||
@@ -4129,10 +4129,10 @@ async fn new_default_turn_uses_config_aware_skills_for_role_overrides() {
|
||||
.skills_for_cwd(
|
||||
&crate::skills_load_input_from_config(
|
||||
&parent_config,
|
||||
crate::skills::EnvironmentPathRef::new(
|
||||
Some(crate::skills::EnvironmentPathRef::new(
|
||||
Arc::clone(&skill_fs),
|
||||
parent_config.cwd.clone(),
|
||||
),
|
||||
)),
|
||||
session
|
||||
.services
|
||||
.environment_manager
|
||||
@@ -4709,7 +4709,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
);
|
||||
let skills_input = crate::skills_load_input_from_config(
|
||||
&per_turn_config,
|
||||
cwd,
|
||||
Some(cwd),
|
||||
services
|
||||
.environment_manager
|
||||
.try_local_environment()
|
||||
@@ -6562,7 +6562,7 @@ where
|
||||
);
|
||||
let skills_input = crate::skills_load_input_from_config(
|
||||
&per_turn_config,
|
||||
cwd,
|
||||
Some(cwd),
|
||||
services
|
||||
.environment_manager
|
||||
.try_local_environment()
|
||||
@@ -7255,6 +7255,9 @@ async fn build_initial_context_trims_skill_metadata_from_context_window_budget()
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/admin-skill/SKILL.md").abs(),
|
||||
),
|
||||
path_to_skills_md: test_path_buf("/tmp/admin-skill/SKILL.md").abs(),
|
||||
scope: SkillScope::Admin,
|
||||
plugin_id: None,
|
||||
@@ -7266,6 +7269,9 @@ async fn build_initial_context_trims_skill_metadata_from_context_window_budget()
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
),
|
||||
path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -7302,6 +7308,9 @@ fn emit_thread_start_skill_metrics_records_enabled_kept_and_truncated_values() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
),
|
||||
path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -7347,6 +7356,9 @@ fn emit_thread_start_skill_metrics_records_description_truncated_chars_without_o
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/alpha-skill/SKILL.md").abs(),
|
||||
),
|
||||
path_to_skills_md: test_path_buf("/tmp/alpha-skill/SKILL.md").abs(),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -7358,6 +7370,9 @@ fn emit_thread_start_skill_metrics_records_description_truncated_chars_without_o
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/beta-skill/SKILL.md").abs(),
|
||||
),
|
||||
path_to_skills_md: test_path_buf("/tmp/beta-skill/SKILL.md").abs(),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
@@ -7406,6 +7421,9 @@ async fn build_initial_context_emits_thread_start_skill_warning_on_repeated_buil
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/admin-skill/SKILL.md").abs(),
|
||||
),
|
||||
path_to_skills_md: test_path_buf("/tmp/admin-skill/SKILL.md").abs(),
|
||||
scope: SkillScope::Admin,
|
||||
plugin_id: None,
|
||||
@@ -7417,6 +7435,9 @@ async fn build_initial_context_emits_thread_start_skill_warning_on_repeated_buil
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
),
|
||||
path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs(),
|
||||
scope: SkillScope::Repo,
|
||||
plugin_id: None,
|
||||
|
||||
@@ -684,36 +684,28 @@ impl Session {
|
||||
turn_environment.cwd.clone(),
|
||||
)
|
||||
});
|
||||
let skills_outcome = if let Some(path_ref) = path_ref {
|
||||
// Workspace/repo skill roots use the selected turn environment path above, while
|
||||
// user/system/plugin skill roots still read from the available local filesystem.
|
||||
let local_file_system = self
|
||||
.services
|
||||
.environment_manager
|
||||
.try_local_environment()
|
||||
.map(|environment| environment.get_filesystem());
|
||||
let plugins_input = per_turn_config.plugins_config_input();
|
||||
let plugin_outcome = self
|
||||
.services
|
||||
.plugins_manager
|
||||
.plugins_for_config(&plugins_input)
|
||||
.await;
|
||||
let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots();
|
||||
let skills_input = skills_load_input_from_config(
|
||||
&per_turn_config,
|
||||
path_ref,
|
||||
local_file_system,
|
||||
effective_skill_roots,
|
||||
);
|
||||
Arc::new(
|
||||
self.services
|
||||
.skills_manager
|
||||
.skills_for_config(&skills_input)
|
||||
.await,
|
||||
)
|
||||
} else {
|
||||
Arc::new(SkillLoadOutcome::default())
|
||||
};
|
||||
// Workspace/repo skill roots use the selected turn environment path above when present,
|
||||
// while user/system/plugin skill roots still read from the local-authority filesystem.
|
||||
let local_file_system = Some(Arc::clone(&codex_exec_server::LOCAL_FS));
|
||||
let plugins_input = per_turn_config.plugins_config_input();
|
||||
let plugin_outcome = self
|
||||
.services
|
||||
.plugins_manager
|
||||
.plugins_for_config(&plugins_input)
|
||||
.await;
|
||||
let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots();
|
||||
let skills_input = skills_load_input_from_config(
|
||||
&per_turn_config,
|
||||
path_ref,
|
||||
local_file_system,
|
||||
effective_skill_roots,
|
||||
);
|
||||
let skills_outcome = Arc::new(
|
||||
self.services
|
||||
.skills_manager
|
||||
.skills_for_config(&skills_input)
|
||||
.await,
|
||||
);
|
||||
let goal_tools_supported = !per_turn_config.ephemeral && self.state_db().is_some();
|
||||
let mut turn_context: TurnContext = Self::make_turn_context(
|
||||
self.thread_id(),
|
||||
|
||||
@@ -38,7 +38,7 @@ pub use codex_core_skills::system;
|
||||
|
||||
pub(crate) fn skills_load_input_from_config(
|
||||
config: &Config,
|
||||
env_path: EnvironmentPathRef,
|
||||
env_path: Option<EnvironmentPathRef>,
|
||||
local_file_system: Option<Arc<dyn ExecutorFileSystem>>,
|
||||
effective_skill_roots: Vec<PluginSkillRoot>,
|
||||
) -> SkillsLoadInput {
|
||||
@@ -57,10 +57,17 @@ pub(crate) async fn maybe_emit_implicit_skill_invocation(
|
||||
command: &str,
|
||||
workdir: &AbsolutePathBuf,
|
||||
) {
|
||||
let workdir = turn_context
|
||||
.environments
|
||||
.primary()
|
||||
.map(|environment| {
|
||||
EnvironmentPathRef::new(environment.environment.get_filesystem(), workdir.clone())
|
||||
})
|
||||
.unwrap_or_else(|| EnvironmentPathRef::local(workdir.clone()));
|
||||
let Some(candidate) = detect_implicit_skill_invocation_for_command(
|
||||
turn_context.turn_skills.outcome.as_ref(),
|
||||
command,
|
||||
workdir,
|
||||
&workdir,
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -674,7 +674,6 @@ pub(super) async fn fetch_skills_list(
|
||||
request_id,
|
||||
params: SkillsListParams {
|
||||
cwds: vec![cwd],
|
||||
environment_id: None,
|
||||
force_reload: true,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -621,7 +621,6 @@ impl App {
|
||||
app_server
|
||||
.skills_list(codex_app_server_protocol::SkillsListParams {
|
||||
cwds: cwds.clone(),
|
||||
environment_id: None,
|
||||
force_reload: *force_reload,
|
||||
})
|
||||
.await,
|
||||
|
||||
@@ -6255,6 +6255,7 @@ mod tests {
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: skill_path.clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(skill_path.clone()),
|
||||
scope: crate::test_support::skill_scope_user(),
|
||||
plugin_id: None,
|
||||
}]));
|
||||
@@ -6298,6 +6299,7 @@ mod tests {
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: skill_path.clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(skill_path.clone()),
|
||||
scope: crate::test_support::skill_scope_repo(),
|
||||
plugin_id: None,
|
||||
}]));
|
||||
@@ -6390,6 +6392,9 @@ mod tests {
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: test_path_buf("/tmp/repo/google-calendar/SKILL.md").abs(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/repo/google-calendar/SKILL.md").abs(),
|
||||
),
|
||||
scope: crate::test_support::skill_scope_repo(),
|
||||
plugin_id: None,
|
||||
}]));
|
||||
|
||||
@@ -2577,6 +2577,9 @@ mod tests {
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: test_path_buf("/tmp/test-skill/SKILL.md").abs(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(
|
||||
test_path_buf("/tmp/test-skill/SKILL.md").abs(),
|
||||
),
|
||||
scope: crate::test_support::skill_scope_user(),
|
||||
plugin_id: None,
|
||||
}]),
|
||||
|
||||
@@ -242,6 +242,9 @@ fn protocol_skill_to_core(skill: &ProtocolSkillMetadata) -> Option<SkillMetadata
|
||||
}),
|
||||
policy: None,
|
||||
path_to_skills_md: skill.path.clone(),
|
||||
// TODO: `skills/list` is local-only until its response carries source authority alongside
|
||||
// the raw path; consume that authority here before supporting non-local listed skills.
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(skill.path.clone()),
|
||||
scope,
|
||||
plugin_id: None,
|
||||
})
|
||||
|
||||
@@ -548,7 +548,8 @@ async fn submission_prefers_selected_duplicate_skill_path() {
|
||||
interface: None,
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: repo_skill_path,
|
||||
path_to_skills_md: repo_skill_path.clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(repo_skill_path),
|
||||
scope: crate::test_support::skill_scope_repo(),
|
||||
plugin_id: None,
|
||||
},
|
||||
@@ -560,6 +561,7 @@ async fn submission_prefers_selected_duplicate_skill_path() {
|
||||
dependencies: None,
|
||||
policy: None,
|
||||
path_to_skills_md: user_skill_path.clone(),
|
||||
source_path: codex_exec_server::EnvironmentPathRef::local(user_skill_path.clone()),
|
||||
scope: crate::test_support::skill_scope_user(),
|
||||
plugin_id: None,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user