From f5562abf1db80d24afa0a28636ec235ad1cff557 Mon Sep 17 00:00:00 2001 From: starr-openai Date: Thu, 28 May 2026 21:51:37 -0700 Subject: [PATCH] Render multi-environment skills with env context --- codex-rs/core-plugins/src/loader.rs | 1 + codex-rs/core-skills/src/injection.rs | 12 +- codex-rs/core-skills/src/injection_tests.rs | 4 +- .../core-skills/src/invocation_utils_tests.rs | 4 +- codex-rs/core-skills/src/lib.rs | 1 + codex-rs/core-skills/src/loader.rs | 96 ++++--- codex-rs/core-skills/src/loader_tests.rs | 158 ++++++++--- codex-rs/core-skills/src/manager.rs | 26 +- codex-rs/core-skills/src/manager_tests.rs | 21 +- codex-rs/core-skills/src/model.rs | 66 +---- codex-rs/core-skills/src/render.rs | 254 ++++++++++++++---- .../context/available_skills_instructions.rs | 9 +- codex-rs/core/src/session/mod.rs | 5 + codex-rs/core/src/session/tests.rs | 44 ++- codex-rs/core/src/session/turn_context.rs | 25 +- codex-rs/core/src/skills.rs | 20 +- codex-rs/tui/src/bottom_pane/chat_composer.rs | 16 +- codex-rs/tui/src/bottom_pane/mod.rs | 6 +- codex-rs/tui/src/chatwidget/skills.rs | 4 +- .../chatwidget/tests/composer_submission.rs | 8 +- 20 files changed, 547 insertions(+), 233 deletions(-) diff --git a/codex-rs/core-plugins/src/loader.rs b/codex-rs/core-plugins/src/loader.rs index ae71568ae9..615a1c24ff 100644 --- a/codex-rs/core-plugins/src/loader.rs +++ b/codex-rs/core-plugins/src/loader.rs @@ -653,6 +653,7 @@ pub async fn load_plugin_skills( .into_iter() .map(|path| SkillRoot { path: plugin_root.with_path(path), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: Some(plugin_id.as_key()), plugin_root: Some(plugin_root.clone()), diff --git a/codex-rs/core-skills/src/injection.rs b/codex-rs/core-skills/src/injection.rs index 45979fa5c4..21ab1377c8 100644 --- a/codex-rs/core-skills/src/injection.rs +++ b/codex-rs/core-skills/src/injection.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; use std::collections::HashSet; -use std::sync::Arc; use crate::SkillLoadOutcome; use crate::SkillMetadata; @@ -9,7 +8,6 @@ use codex_analytics::AnalyticsEventsClient; use codex_analytics::InvocationType; use codex_analytics::SkillInvocation; use codex_analytics::TrackEventsContext; -use codex_exec_server::LOCAL_FS; use codex_otel::SessionTelemetry; use codex_protocol::user_input::UserInput; use codex_utils_absolute_path::AbsolutePathBuf; @@ -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 { diff --git a/codex-rs/core-skills/src/injection_tests.rs b/codex-rs/core-skills/src/injection_tests.rs index 78aa195895..9972d67dc8 100644 --- a/codex-rs/core-skills/src/injection_tests.rs +++ b/codex-rs/core-skills/src/injection_tests.rs @@ -14,7 +14,9 @@ fn make_skill(name: &str, path: &str) -> SkillMetadata { interface: None, dependencies: None, policy: None, - path_to_skills_md: test_path_buf(path).abs(), + path_to_skills_md: test_path_buf(path).abs().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(test_path_buf(path).abs()), + environment_id: "local".to_string(), scope: codex_protocol::protocol::SkillScope::User, plugin_id: None, } diff --git a/codex-rs/core-skills/src/invocation_utils_tests.rs b/codex-rs/core-skills/src/invocation_utils_tests.rs index f6e3883c16..8a3dfc7f2d 100644 --- a/codex-rs/core-skills/src/invocation_utils_tests.rs +++ b/codex-rs/core-skills/src/invocation_utils_tests.rs @@ -19,7 +19,9 @@ fn test_skill_metadata(skill_doc_path: AbsolutePathBuf) -> SkillMetadata { interface: None, dependencies: None, policy: None, - path_to_skills_md: skill_doc_path, + path_to_skills_md: skill_doc_path.clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(skill_doc_path), + environment_id: "local".to_string(), scope: codex_protocol::protocol::SkillScope::User, plugin_id: None, } diff --git a/codex-rs/core-skills/src/lib.rs b/codex-rs/core-skills/src/lib.rs index 1577662bc5..9396da1534 100644 --- a/codex-rs/core-skills/src/lib.rs +++ b/codex-rs/core-skills/src/lib.rs @@ -24,6 +24,7 @@ pub use render::SKILLS_HOW_TO_USE_WITH_ABSOLUTE_PATHS; pub use render::SKILLS_HOW_TO_USE_WITH_ALIASES; pub use render::SKILLS_INTRO_WITH_ABSOLUTE_PATHS; pub use render::SKILLS_INTRO_WITH_ALIASES; +pub use render::SkillEnvironmentRender; pub use render::SkillMetadataBudget; pub use render::SkillRenderReport; pub use render::build_available_skills; diff --git a/codex-rs/core-skills/src/loader.rs b/codex-rs/core-skills/src/loader.rs index fab660d11e..1e8453985f 100644 --- a/codex-rs/core-skills/src/loader.rs +++ b/codex-rs/core-skills/src/loader.rs @@ -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; @@ -152,27 +151,32 @@ impl Error for SkillParseError {} pub struct SkillRoot { pub path: EnvironmentPathRef, + pub environment_id: String, pub scope: SkillScope, pub plugin_id: Option, pub plugin_root: Option, } +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +pub struct SkillEnvironment { + pub environment_id: String, + pub path: EnvironmentPathRef, +} + pub async fn load_skills_from_roots(roots: I) -> SkillLoadOutcome where I: IntoIterator, { let mut outcome = SkillLoadOutcome::default(); - let mut skill_roots: Vec = Vec::new(); - let mut skill_root_by_path: HashMap = HashMap::new(); - let mut file_systems_by_skill_path: HashMap> = - HashMap::new(); + let mut skill_roots: Vec = Vec::new(); + let mut skill_root_by_path: HashMap = 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, + &root.environment_id, root.scope, root.plugin_id.as_deref(), root.plugin_root.as_ref(), @@ -180,34 +184,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 = HashSet::new(); + let mut seen: HashSet = HashSet::new(); outcome .skills - .retain(|skill| seen.insert(skill.path_to_skills_md.clone())); - let retained_skill_paths: HashSet = outcome + .retain(|skill| seen.insert(skill.source_path.clone())); + let retained_skill_paths: HashSet = 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 = skill_root_by_path.values().cloned().collect(); + let used_roots: HashSet = 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,7 +229,7 @@ where } pub(crate) async fn skill_roots( - env_path: &EnvironmentPathRef, + env_paths: &[SkillEnvironment], local_file_system: Option<&Arc>, config_layer_stack: &ConfigLayerStack, plugin_skill_roots: Vec, @@ -242,7 +241,7 @@ pub(crate) async fn skill_roots( let home_dir = home_dir().and_then(|path| AbsolutePathBuf::from_absolute_path_checked(path).ok()); skill_roots_with_home_dir( - env_path, + env_paths, local_file_system, config_layer_stack, home_dir.as_ref(), @@ -253,7 +252,7 @@ pub(crate) async fn skill_roots( } async fn skill_roots_with_home_dir( - env_path: &EnvironmentPathRef, + env_paths: &[SkillEnvironment], local_file_system: Option<&Arc>, config_layer_stack: &ConfigLayerStack, home_dir: Option<&AbsolutePathBuf>, @@ -262,7 +261,10 @@ async fn skill_roots_with_home_dir( ) -> Vec { // 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_paths + .iter() + .flat_map(|env_path| repo_config_skill_roots(env_path, config_layer_stack)) + .collect::>(); roots.extend(local_skill_roots( local_file_system, config_layer_stack, @@ -270,7 +272,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); + for env_path in env_paths { + roots.extend(repo_agents_skill_roots(env_path, config_layer_stack).await); + } dedupe_skill_roots_by_path(&mut roots); roots } @@ -311,6 +315,7 @@ fn local_skill_roots( Arc::clone(local_file_system), config_folder.join(SKILLS_DIR_NAME), ), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, plugin_root: None, @@ -323,6 +328,7 @@ fn local_skill_roots( Arc::clone(local_file_system), home_dir.join(AGENTS_DIR_NAME).join(SKILLS_DIR_NAME), ), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, plugin_root: None, @@ -336,6 +342,7 @@ fn local_skill_roots( Arc::clone(local_file_system), system_cache_root_dir(&config_folder), ), + environment_id: "local".to_string(), scope: SkillScope::System, plugin_id: None, plugin_root: None, @@ -349,6 +356,7 @@ fn local_skill_roots( Arc::clone(local_file_system), config_folder.join(SKILLS_DIR_NAME), ), + environment_id: "local".to_string(), scope: SkillScope::Admin, plugin_id: None, plugin_root: None, @@ -365,6 +373,7 @@ fn local_skill_roots( // Plugin discovery is currently local-only; multi-env plugin skill loading should be an // explicit future change rather than inheriting the selected repo environment here. path: EnvironmentPathRef::new(Arc::clone(local_file_system), root.path), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: Some(root.plugin_id), plugin_root: Some(EnvironmentPathRef::new( @@ -383,7 +392,7 @@ fn local_skill_roots( } fn repo_config_skill_roots( - env_path: &EnvironmentPathRef, + env_path: &SkillEnvironment, config_layer_stack: &ConfigLayerStack, ) -> Vec { // Project config layers describe workspace-local `.codex/skills` directories. Their absolute @@ -400,7 +409,8 @@ fn repo_config_skill_roots( SkillRoot { // Project and repo `.agents` roots belong to the selected environment because // their absolute paths are only meaningful within that environment's cwd/repo. - path: env_path.with_path(config_folder.join(SKILLS_DIR_NAME)), + path: env_path.path.with_path(config_folder.join(SKILLS_DIR_NAME)), + environment_id: env_path.environment_id.clone(), scope: SkillScope::Repo, plugin_id: None, plugin_root: None, @@ -417,20 +427,23 @@ fn repo_config_skill_roots( } async fn repo_agents_skill_roots( - env_path: &EnvironmentPathRef, + env_path: &SkillEnvironment, config_layer_stack: &ConfigLayerStack, ) -> Vec { // Discover repo `.agents/skills` folders by walking from the selected environment's project // root to its cwd; this must never consult the local filesystem for remote workspaces. let project_root_markers = project_root_markers_from_stack(config_layer_stack); - let project_root = find_project_root(env_path, &project_root_markers).await; - let dirs = dirs_between_project_root_and_cwd(env_path.path(), project_root.path()); + let project_root = find_project_root(&env_path.path, &project_root_markers).await; + let dirs = dirs_between_project_root_and_cwd(env_path.path.path(), project_root.path()); let mut roots = Vec::new(); for dir in dirs { - let agents_skills = env_path.with_path(dir.join(AGENTS_DIR_NAME).join(SKILLS_DIR_NAME)); + let agents_skills = env_path + .path + .with_path(dir.join(AGENTS_DIR_NAME).join(SKILLS_DIR_NAME)); match agents_skills.metadata(/*sandbox*/ None).await { Ok(metadata) if metadata.is_directory => roots.push(SkillRoot { path: agents_skills, + environment_id: env_path.environment_id.clone(), scope: SkillScope::Repo, plugin_id: None, plugin_root: None, @@ -529,6 +542,7 @@ fn canonicalize_for_skill_identity(path: &AbsolutePathBuf) -> AbsolutePathBuf { async fn discover_skills_under_root( root: &EnvironmentPathRef, + environment_id: &str, scope: SkillScope, plugin_id: Option<&str>, plugin_root: Option<&EnvironmentPathRef>, @@ -656,7 +670,15 @@ async fn discover_skills_under_root( } if metadata.is_file && file_name == SKILLS_FILENAME { - match parse_skill_file(&path, scope, plugin_id, plugin_root.as_ref()).await { + match parse_skill_file( + &path, + environment_id, + scope, + plugin_id, + plugin_root.as_ref(), + ) + .await + { Ok(skill) => { outcome.skills.push(skill); } @@ -684,6 +706,7 @@ async fn discover_skills_under_root( async fn parse_skill_file( skill_path: &EnvironmentPathRef, + environment_id: &str, scope: SkillScope, plugin_id: Option<&str>, plugin_root: Option<&EnvironmentPathRef>, @@ -742,7 +765,9 @@ 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), + environment_id: environment_id.to_string(), scope, plugin_id: plugin_id.map(str::to_string), }) @@ -1135,7 +1160,10 @@ 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, + &[SkillEnvironment { + environment_id: "local".to_string(), + path: path_ref, + }], Some(&local_file_system), config_layer_stack, home_dir, diff --git a/codex-rs/core-skills/src/loader_tests.rs b/codex-rs/core-skills/src/loader_tests.rs index ce57f8cb84..e585250dd4 100644 --- a/codex-rs/core-skills/src/loader_tests.rs +++ b/codex-rs/core-skills/src/loader_tests.rs @@ -305,7 +305,10 @@ async fn skill_roots_bind_repo_and_local_roots_to_their_own_file_systems() -> an let local_file_system: Arc = Arc::new(LocalFileSystem::unsandboxed()); let env_path = EnvironmentPathRef::new(env_file_system.clone(), cfg.cwd.clone()); let roots = super::skill_roots( - &env_path, + &[super::SkillEnvironment { + environment_id: "devbox".to_string(), + path: env_path.clone(), + }], Some(&local_file_system), &cfg.config_layer_stack, Vec::new(), @@ -328,7 +331,10 @@ async fn skill_roots_bind_repo_and_local_roots_to_their_own_file_systems() -> an )); let roots_without_local = super::skill_roots( - &env_path, + &[super::SkillEnvironment { + environment_id: "devbox".to_string(), + path: env_path.clone(), + }], /*local_file_system*/ None, &cfg.config_layer_stack, Vec::new(), @@ -396,7 +402,9 @@ async fn loads_skills_from_home_agents_dir_for_user_scope() -> anyhow::Result<() interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -534,7 +542,9 @@ async fn loads_skill_dependencies_metadata_from_yaml() { ], }), policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -590,7 +600,11 @@ interface: }), dependencies: None, policy: None, - path_to_skills_md: normalized(skill_path.as_path()), + path_to_skills_md: normalized(skill_path.as_path()).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized( + skill_path.as_path() + )), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -744,7 +758,9 @@ async fn accepts_icon_paths_under_assets_dir() { }), dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -785,7 +801,9 @@ async fn ignores_invalid_brand_color() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -839,7 +857,9 @@ async fn ignores_default_prompt_over_max_length() { }), dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -881,7 +901,9 @@ async fn drops_interface_when_icons_are_invalid() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -913,6 +935,7 @@ interface: let plugin_root_abs = plugin_root.abs(); let outcome = load_skills_from_roots([SkillRoot { path: local_env_path(plugin_root.join("skills").abs()), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: Some("twilio-developer-kit@test".to_string()), plugin_root: Some(local_env_path(plugin_root_abs.clone())), @@ -941,7 +964,9 @@ interface: }), dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: Some("twilio-developer-kit@test".to_string()), }] @@ -969,6 +994,7 @@ interface: let outcome = load_skills_from_roots([SkillRoot { path: local_env_path(plugin_root.join("skills").abs()), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: Some("twilio-developer-kit@test".to_string()), plugin_root: Some(local_env_path(plugin_root.abs())), @@ -989,7 +1015,9 @@ interface: interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: Some("twilio-developer-kit@test".to_string()), }] @@ -1034,7 +1062,11 @@ async fn loads_skills_via_symlinked_subdir_for_user_scope() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&shared_skill_path), + path_to_skills_md: normalized(&shared_skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized( + &shared_skill_path + )), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -1094,7 +1126,9 @@ async fn does_not_loop_on_symlink_cycle_for_user_scope() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -1130,7 +1164,11 @@ async fn loads_skills_via_symlinked_subdir_for_admin_scope() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&shared_skill_path), + path_to_skills_md: normalized(&shared_skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized( + &shared_skill_path + )), + environment_id: "local".to_string(), scope: SkillScope::Admin, plugin_id: None, }] @@ -1170,7 +1208,11 @@ async fn loads_skills_via_symlinked_subdir_for_repo_scope() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&linked_skill_path), + path_to_skills_md: normalized(&linked_skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized( + &linked_skill_path + )), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }] @@ -1234,7 +1276,11 @@ async fn respects_max_scan_depth_for_user_scope() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&within_depth_path), + path_to_skills_md: normalized(&within_depth_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized( + &within_depth_path + )), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -1262,7 +1308,9 @@ async fn loads_valid_skill() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -1295,7 +1343,9 @@ async fn falls_back_to_directory_name_when_skill_name_is_missing() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -1320,6 +1370,7 @@ async fn namespaces_plugin_skills_using_plugin_name() { let outcome = load_skills_from_roots([SkillRoot { path: local_env_path(plugin_root.join("skills").abs()), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: Some("sample@test".to_string()), plugin_root: Some(local_env_path(plugin_root.abs())), @@ -1340,7 +1391,9 @@ async fn namespaces_plugin_skills_using_plugin_name() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: Some("sample@test".to_string()), }] @@ -1372,7 +1425,9 @@ async fn loads_short_description_from_metadata() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }] @@ -1485,7 +1540,9 @@ async fn loads_skills_from_repo_root() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }] @@ -1521,7 +1578,9 @@ async fn loads_skills_from_agents_dir_without_codex_dir() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }] @@ -1575,7 +1634,11 @@ async fn loads_skills_from_all_codex_dirs_under_project_root() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&nested_skill_path), + path_to_skills_md: normalized(&nested_skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized( + &nested_skill_path + )), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }, @@ -1586,7 +1649,11 @@ async fn loads_skills_from_all_codex_dirs_under_project_root() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&root_skill_path), + path_to_skills_md: normalized(&root_skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized( + &root_skill_path + )), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }, @@ -1626,7 +1693,9 @@ async fn loads_skills_from_codex_dir_when_not_git_repo() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }] @@ -1642,12 +1711,14 @@ async fn deduplicates_by_path_preferring_first_root() { let outcome = load_skills_from_roots([ SkillRoot { path: local_env_path(root.path().abs()), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, plugin_root: None, }, SkillRoot { path: local_env_path(root.path().abs()), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, plugin_root: None, @@ -1669,7 +1740,9 @@ async fn deduplicates_by_path_preferring_first_root() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }] @@ -1711,7 +1784,11 @@ async fn keeps_duplicate_names_from_repo_and_user() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&repo_skill_path), + path_to_skills_md: normalized(&repo_skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized( + &repo_skill_path + )), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }, @@ -1722,7 +1799,11 @@ async fn keeps_duplicate_names_from_repo_and_user() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&user_skill_path), + path_to_skills_md: normalized(&user_skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized( + &user_skill_path + )), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, }, @@ -1785,7 +1866,9 @@ async fn keeps_duplicate_names_from_nested_codex_dirs() { interface: None, dependencies: None, policy: None, - path_to_skills_md: first_path, + path_to_skills_md: first_path.clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(first_path), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }, @@ -1796,7 +1879,9 @@ async fn keeps_duplicate_names_from_nested_codex_dirs() { interface: None, dependencies: None, policy: None, - path_to_skills_md: second_path, + path_to_skills_md: second_path.clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(second_path), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }, @@ -1868,7 +1953,9 @@ async fn loads_skills_when_cwd_is_file_in_repo() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }] @@ -1927,7 +2014,9 @@ async fn loads_skills_from_system_cache_when_present() { interface: None, dependencies: None, policy: None, - path_to_skills_md: normalized(&skill_path), + path_to_skills_md: normalized(&skill_path).clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(normalized(&skill_path)), + environment_id: "local".to_string(), scope: SkillScope::System, plugin_id: None, }] @@ -1942,7 +2031,10 @@ 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 = super::skill_roots( - &cwd, + &[super::SkillEnvironment { + environment_id: "local".to_string(), + path: cwd.clone(), + }], Some(&local_file_system), &cfg.config_layer_stack, Vec::new(), diff --git a/codex-rs/core-skills/src/manager.rs b/codex-rs/core-skills/src/manager.rs index 420ef2cbab..07ac1f36f4 100644 --- a/codex-rs/core-skills/src/manager.rs +++ b/codex-rs/core-skills/src/manager.rs @@ -16,6 +16,7 @@ use crate::build_implicit_skill_path_indexes; use crate::config_rules::SkillConfigRules; use crate::config_rules::resolve_disabled_skill_paths; use crate::config_rules::skill_config_rules_from_stack; +use crate::loader::SkillEnvironment; use crate::loader::SkillRoot; use crate::loader::load_skills_from_roots; use crate::loader::skill_roots; @@ -27,7 +28,7 @@ use codex_exec_server::ExecutorFileSystem; #[derive(Clone)] pub struct SkillsLoadInput { - pub env_path: EnvironmentPathRef, + pub env_paths: Vec, /// Local user/system/plugin skill roots are read from this filesystem for now. pub local_file_system: Option>, pub effective_skill_roots: Vec, @@ -38,7 +39,7 @@ pub struct SkillsLoadInput { impl std::fmt::Debug for SkillsLoadInput { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("SkillsLoadInput") - .field("env_path", &self.env_path) + .field("env_paths", &self.env_paths.len()) .field("has_local_file_system", &self.local_file_system.is_some()) .field("effective_skill_roots", &self.effective_skill_roots) .field("config_layer_stack", &self.config_layer_stack) @@ -49,14 +50,14 @@ impl std::fmt::Debug for SkillsLoadInput { impl SkillsLoadInput { pub fn new( - env_path: EnvironmentPathRef, + env_paths: Vec, local_file_system: Option>, effective_skill_roots: Vec, config_layer_stack: ConfigLayerStack, bundled_skills_enabled: bool, ) -> Self { Self { - env_path, + env_paths, local_file_system, effective_skill_roots, config_layer_stack, @@ -136,7 +137,7 @@ impl SkillsManager { pub async fn skill_roots_for_config(&self, input: &SkillsLoadInput) -> Vec { let mut roots = skill_roots( - &input.env_path, + &input.env_paths, input.local_file_system.as_ref(), &input.config_layer_stack, input.effective_skill_roots.clone(), @@ -155,7 +156,7 @@ impl SkillsManager { force_reload: bool, ) -> SkillLoadOutcome { let path_ref_cache_key = SkillsPathCacheKey { - env_path: input.env_path.clone(), + env_paths: input.env_paths.clone(), local_file_system: input .local_file_system .as_ref() @@ -168,7 +169,7 @@ impl SkillsManager { } let mut roots = skill_roots( - &input.env_path, + &input.env_paths, input.local_file_system.as_ref(), &input.config_layer_stack, input.effective_skill_roots.clone(), @@ -254,7 +255,7 @@ impl SkillsManager { #[derive(Clone, Debug, Eq, Hash, PartialEq)] struct SkillsPathCacheKey { - env_path: EnvironmentPathRef, + env_paths: Vec, local_file_system: Option, } @@ -289,7 +290,7 @@ impl std::fmt::Debug for ExecutorFileSystemRef { #[derive(Debug, Clone, PartialEq, Eq, Hash)] struct ConfigSkillsCacheKey { - roots: Vec<(EnvironmentPathRef, u8, Option)>, + roots: Vec<(EnvironmentPathRef, String, u8, Option)>, skill_config_rules: SkillConfigRules, } @@ -329,7 +330,12 @@ fn config_skills_cache_key( SkillScope::System => 2, SkillScope::Admin => 3, }; - (root.path.clone(), scope_rank, root.plugin_id.clone()) + ( + root.path.clone(), + root.environment_id.clone(), + scope_rank, + root.plugin_id.clone(), + ) }) .collect(), skill_config_rules: skill_config_rules.clone(), diff --git a/codex-rs/core-skills/src/manager_tests.rs b/codex-rs/core-skills/src/manager_tests.rs index 78fb26bc43..8707aaad57 100644 --- a/codex-rs/core-skills/src/manager_tests.rs +++ b/codex-rs/core-skills/src/manager_tests.rs @@ -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,9 @@ 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"), + path_to_skills_md: path.clone(), + source_path: EnvironmentPathRef::local(path), + environment_id: "local".to_string(), scope: SkillScope::User, plugin_id: None, } @@ -98,7 +101,10 @@ fn local_skills_input( ) -> SkillsLoadInput { let path_ref = skill_root_path_ref(cwd); SkillsLoadInput::new( - path_ref, + vec![SkillEnvironment { + environment_id: "local".to_string(), + path: path_ref, + }], Some(Arc::clone(&LOCAL_FS)), effective_skill_roots, config_layer_stack.clone(), @@ -475,7 +481,10 @@ 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()), + vec![SkillEnvironment { + environment_id: "local".to_string(), + path: skill_root_path_ref(cwd.path().abs()), + }], /*local_file_system*/ None, Vec::new(), config_layer_stack.clone(), diff --git a/codex-rs/core-skills/src/model.rs b/codex-rs/core-skills/src/model.rs index 832af06bb4..562925b72e 100644 --- a/codex-rs/core-skills/src/model.rs +++ b/codex-rs/core-skills/src/model.rs @@ -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)] @@ -15,8 +14,12 @@ pub struct SkillMetadata { pub interface: Option, pub dependencies: Option, pub policy: Option, - /// Path to the SKILLS.md file that declares this skill. + /// Path to the SKILL.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, + /// Model-visible environment id for this skill path. + pub environment_id: String, pub scope: SkillScope, pub plugin_id: Option, } @@ -89,9 +92,8 @@ pub struct SkillLoadOutcome { pub skills: Vec, pub errors: Vec, pub disabled_paths: HashSet, - pub(crate) skill_roots: Vec, - pub(crate) skill_root_by_path: Arc>, - pub(crate) file_systems_by_skill_path: SkillFileSystemsByPath, + pub(crate) skill_roots: Vec, + pub(crate) skill_root_by_path: Arc>, pub(crate) implicit_skills_by_scripts_dir: Arc>, pub(crate) implicit_skills_by_doc_path: Arc>, } @@ -118,49 +120,6 @@ impl SkillLoadOutcome { .iter() .map(|skill| (skill, self.is_skill_enabled(skill))) } - - pub(crate) fn file_system_for_skill( - &self, - skill: &SkillMetadata, - ) -> Option> { - self.file_systems_by_skill_path - .get(&skill.path_to_skills_md) - } -} - -#[derive(Clone, Default)] -pub(crate) struct SkillFileSystemsByPath { - values: Arc>>, -} - -impl SkillFileSystemsByPath { - pub(crate) fn new(values: HashMap>) -> Self { - Self { - values: Arc::new(values), - } - } - - fn get(&self, path: &AbsolutePathBuf) -> Option> { - self.values.get(path).map(Arc::clone) - } - - fn retain_paths(&mut self, paths: &HashSet) { - 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 +129,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 = outcome + let retained_paths: HashSet = 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 +142,7 @@ pub fn filter_skill_load_outcome_for_product( .map(|(path, root)| (path.clone(), root.clone())) .collect(), ); - let retained_roots: HashSet = + let retained_roots: HashSet = outcome.skill_root_by_path.values().cloned().collect(); outcome .skill_roots diff --git a/codex-rs/core-skills/src/render.rs b/codex-rs/core-skills/src/render.rs index 28617fb6c4..21bcb8f6db 100644 --- a/codex-rs/core-skills/src/render.rs +++ b/codex-rs/core-skills/src/render.rs @@ -59,7 +59,11 @@ pub const SKILLS_HOW_TO_USE_WITH_ALIASES: &str = r###"- Discovery: The list abov - When variants exist (frameworks, providers, domains), pick only the relevant reference file(s) and note that choice. - Safety and fallback: If a skill can't be applied cleanly (missing files, unclear instructions), state the issue, pick the next-best approach, and continue."###; -pub fn render_available_skills_body(skill_root_lines: &[String], skill_lines: &[String]) -> String { +pub fn render_available_skills_body( + skill_root_lines: &[String], + skill_lines: &[String], + environment_render: SkillEnvironmentRender, +) -> String { let mut lines: Vec = Vec::new(); lines.push("## Skills".to_string()); if skill_root_lines.is_empty() { @@ -79,6 +83,9 @@ pub fn render_available_skills_body(skill_root_lines: &[String], skill_lines: &[ SKILLS_HOW_TO_USE_WITH_ALIASES }; lines.push(how_to_use.to_string()); + if matches!(environment_render, SkillEnvironmentRender::Include) { + lines.push("- Environment selection: When a skill line includes `env`, open that skill and resolve relative paths in that environment.".to_string()); + } format!("\n{}\n", lines.join("\n")) } @@ -136,10 +143,17 @@ pub enum SkillRenderSideEffects<'a> { pub struct AvailableSkills { pub skill_root_lines: Vec, pub skill_lines: Vec, + pub environment_render: SkillEnvironmentRender, pub report: SkillRenderReport, pub warning_message: Option, } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum SkillEnvironmentRender { + Omit, + Include, +} + pub fn default_skill_metadata_budget(context_window: Option) -> SkillMetadataBudget { context_window .and_then(|window| usize::try_from(window).ok()) @@ -160,6 +174,7 @@ pub fn default_skill_metadata_budget(context_window: Option) -> SkillMetada pub fn build_available_skills( outcome: &SkillLoadOutcome, budget: SkillMetadataBudget, + environment_render: SkillEnvironmentRender, side_effects: SkillRenderSideEffects<'_>, ) -> Option { let skills = outcome.allowed_skills_for_implicit_invocation(); @@ -174,18 +189,21 @@ pub fn build_available_skills( return None; } - let absolute_lines = ordered_absolute_skill_lines(&skills); + let absolute_lines = ordered_absolute_skill_lines(&skills, environment_render); let absolute = build_available_skills_from_lines( absolute_lines, skills.len(), budget, SkillPathAliases::default(), + environment_render, )?; let selected = if absolute.report.omitted_count == 0 && absolute.report.truncated_description_chars == 0 { absolute - } else if let Some(aliased) = build_aliased_available_skills(outcome, &skills, budget) { + } else if let Some(aliased) = + build_aliased_available_skills(outcome, &skills, budget, environment_render) + { if aliased_render_is_better(&aliased, &absolute, budget) { aliased } else { @@ -204,6 +222,7 @@ fn build_available_skills_from_lines( total_count: usize, budget: SkillMetadataBudget, path_aliases: SkillPathAliases, + environment_render: SkillEnvironmentRender, ) -> Option { if total_count == 0 { return None; @@ -244,6 +263,7 @@ fn build_available_skills_from_lines( let available = AvailableSkills { skill_root_lines: path_aliases.skill_root_lines, skill_lines, + environment_render, report, warning_message, }; @@ -448,6 +468,7 @@ struct SkillLine<'a> { name: &'a str, description: &'a str, path: String, + environment_id: Option<&'a str>, } struct RenderedSkillLine { @@ -477,18 +498,25 @@ fn sum_description_truncation(rendered: &[RenderedSkillLine]) -> (usize, usize) } impl<'a> SkillLine<'a> { - fn new(skill: &'a SkillMetadata) -> Self { + fn new(skill: &'a SkillMetadata, environment_render: SkillEnvironmentRender) -> Self { Self::with_path( skill, skill.path_to_skills_md.to_string_lossy().replace('\\', "/"), + environment_render, ) } - fn with_path(skill: &'a SkillMetadata, path: String) -> Self { + fn with_path( + skill: &'a SkillMetadata, + path: String, + environment_render: SkillEnvironmentRender, + ) -> Self { Self { name: skill.name.as_str(), description: skill.description.as_str(), path, + environment_id: matches!(environment_render, SkillEnvironmentRender::Include) + .then_some(skill.environment_id.as_str()), } } @@ -521,19 +549,24 @@ impl<'a> SkillLine<'a> { fn render_with_description_chars(&self, description_chars: usize) -> String { if description_chars == 0 { - format!("- {}: (file: {})", self.name, self.path) + self.render_with_description("") } else { let end = self.rendered_description_prefix_len(description_chars); let description = &self.description[..end]; - format!("- {}: {} (file: {})", self.name, description, self.path) + self.render_with_description(description) } } fn render_with_description(&self, description: &str) -> String { - if description.is_empty() { - format!("- {}: (file: {})", self.name, self.path) + let location = if let Some(environment_id) = self.environment_id { + format!("env: {environment_id}, file: {}", self.path) } else { - format!("- {}: {} (file: {})", self.name, description, self.path) + format!("file: {}", self.path) + }; + if description.is_empty() { + format!("- {}: ({location})", self.name) + } else { + format!("- {}: {} ({location})", self.name, description) } } } @@ -639,6 +672,7 @@ fn build_aliased_available_skills( outcome: &SkillLoadOutcome, skills: &[SkillMetadata], budget: SkillMetadataBudget, + environment_render: SkillEnvironmentRender, ) -> Option { let plan = build_alias_plan(outcome, skills, budget)?; if plan.table_cost >= budget.limit() { @@ -653,9 +687,21 @@ fn build_aliased_available_skills( let ordered_skills = ordered_skills_for_budget(skills); let skill_lines = ordered_skills .into_iter() - .map(|skill| SkillLine::with_path(skill, render_skill_path_with_aliases(skill, &plan))) + .map(|skill| { + SkillLine::with_path( + skill, + render_skill_path_with_aliases(skill, &plan), + environment_render, + ) + }) .collect::>(); - build_available_skills_from_lines(skill_lines, skills.len(), adjusted_budget, plan.aliases) + build_available_skills_from_lines( + skill_lines, + skills.len(), + adjusted_budget, + plan.aliases, + environment_render, + ) } #[derive(Debug, Clone, Default, PartialEq, Eq)] @@ -665,8 +711,9 @@ struct SkillPathAliases { struct AliasPlan { aliases: SkillPathAliases, - root_aliases: HashMap, - alias_root_by_path: HashMap, + root_aliases: HashMap, + alias_root_by_path: + HashMap, table_cost: usize, } @@ -677,7 +724,7 @@ fn build_alias_plan( ) -> Option { let skill_paths = skills .iter() - .map(|skill| skill.path_to_skills_md.clone()) + .map(|skill| skill.source_path.clone()) .collect::>(); let skill_root_by_path = outcome .skill_root_by_path @@ -736,9 +783,12 @@ fn build_alias_plan( } fn ordered_alias_roots( - used_roots: &[AbsolutePathBuf], - alias_root_by_skill_root: &HashMap, -) -> Option> { + used_roots: &[codex_exec_server::EnvironmentPathRef], + alias_root_by_skill_root: &HashMap< + codex_exec_server::EnvironmentPathRef, + codex_exec_server::EnvironmentPathRef, + >, +) -> Option> { let mut seen = HashSet::new(); let mut alias_roots = Vec::new(); for root in used_roots { @@ -751,10 +801,10 @@ fn ordered_alias_roots( } fn alias_root_for_skill_root( - root: &AbsolutePathBuf, + root: &codex_exec_server::EnvironmentPathRef, plugin_version_skill_counts: &HashMap, -) -> AbsolutePathBuf { - let Some(plugin_version_base) = plugin_version_base(root.as_path()) else { +) -> codex_exec_server::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 +814,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()) + root.with_path( + plugin_marketplace_base(root.path().as_path()).unwrap_or_else(|| root.path().clone()), + ) } } fn plugin_version_skill_counts_for_skill_roots<'a>( - skill_roots: impl Iterator, + skill_roots: impl Iterator, ) -> HashMap { 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); } @@ -786,19 +838,24 @@ fn aliased_metadata_overhead_cost( skill_root_lines: &[String], ) -> usize { let empty_skill_lines: &[String] = &[]; - let absolute_body = render_available_skills_body(&[], empty_skill_lines); - let aliased_body = render_available_skills_body(skill_root_lines, empty_skill_lines); + let absolute_body = + render_available_skills_body(&[], empty_skill_lines, SkillEnvironmentRender::Omit); + let aliased_body = render_available_skills_body( + skill_root_lines, + empty_skill_lines, + SkillEnvironmentRender::Omit, + ); budget .cost(&aliased_body) .saturating_sub(budget.cost(&absolute_body)) } -fn build_skill_root_lines(roots: &[AbsolutePathBuf]) -> Vec { +fn build_skill_root_lines(roots: &[codex_exec_server::EnvironmentPathRef]) -> Vec { 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 +897,12 @@ fn render_skill_path_with_aliases(skill: &SkillMetadata, plan: &AliasPlan) -> St } fn outcome_relative_skill_path(skill: &SkillMetadata, plan: &AliasPlan) -> Option { - 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}")) @@ -875,10 +932,13 @@ fn available_skills_cost(budget: SkillMetadataBudget, available: &AvailableSkill metadata_cost.saturating_add(lines_cost(budget, &available.skill_lines)) } -fn ordered_absolute_skill_lines(skills: &[SkillMetadata]) -> Vec> { +fn ordered_absolute_skill_lines( + skills: &[SkillMetadata], + environment_render: SkillEnvironmentRender, +) -> Vec> { ordered_skills_for_budget(skills) .into_iter() - .map(SkillLine::new) + .map(|skill| SkillLine::new(skill, environment_render)) .collect() } @@ -920,7 +980,13 @@ mod tests { interface: None, dependencies: None, policy: None, - path_to_skills_md: test_path_buf(&format!("/tmp/{name}/SKILL.md")).abs(), + path_to_skills_md: test_path_buf(&format!("/tmp/{name}/SKILL.md")) + .abs() + .clone(), + source_path: codex_exec_server::EnvironmentPathRef::local( + test_path_buf(&format!("/tmp/{name}/SKILL.md")).abs(), + ), + environment_id: "local".to_string(), scope, plugin_id: None, } @@ -937,7 +1003,7 @@ mod tests { } fn expected_skill_line(skill: &SkillMetadata, description: &str) -> String { - SkillLine::new(skill).render_with_description(description) + SkillLine::new(skill, SkillEnvironmentRender::Omit).render_with_description(description) } fn normalized_path(path: &AbsolutePathBuf) -> String { @@ -948,6 +1014,10 @@ mod tests { skills: Vec, roots: Vec, ) -> SkillLoadOutcome { + let roots = roots + .into_iter() + .map(codex_exec_server::EnvironmentPathRef::local) + .collect::>(); let skill_root_by_path = skills .iter() .filter_map(|skill| { @@ -957,9 +1027,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::>(); SkillLoadOutcome { @@ -975,10 +1045,11 @@ mod tests { budget: SkillMetadataBudget, ) -> Option { build_available_skills_from_lines( - ordered_absolute_skill_lines(skills), + ordered_absolute_skill_lines(skills, SkillEnvironmentRender::Omit), skills.len(), budget, SkillPathAliases::default(), + SkillEnvironmentRender::Omit, ) } @@ -1010,9 +1081,10 @@ mod tests { fn budgeted_rendering_truncates_descriptions_equally_before_omitting_skills() { let alpha = make_skill_with_description("alpha-skill", SkillScope::Repo, "abcdef"); let beta = make_skill_with_description("beta-skill", SkillScope::Repo, "uvwxyz"); - let minimum_cost = SkillLine::new(&alpha) + let minimum_cost = SkillLine::new(&alpha, SkillEnvironmentRender::Omit) .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)) - + SkillLine::new(&beta).minimum_cost(SkillMetadataBudget::Characters(usize::MAX)); + + SkillLine::new(&beta, SkillEnvironmentRender::Omit) + .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)); let budget = SkillMetadataBudget::Characters(minimum_cost + 6); let rendered = build_available_skills_from_metadata(&[beta.clone(), alpha.clone()], budget) @@ -1035,9 +1107,10 @@ mod tests { fn budgeted_rendering_does_not_warn_when_average_description_truncation_is_within_threshold() { let alpha = make_skill_with_description("alpha-skill", SkillScope::Repo, "abcdefghij"); let beta = make_skill_with_description("beta-skill", SkillScope::Repo, "uvwxyzabcd"); - let minimum_cost = SkillLine::new(&alpha) + let minimum_cost = SkillLine::new(&alpha, SkillEnvironmentRender::Omit) .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)) - + SkillLine::new(&beta).minimum_cost(SkillMetadataBudget::Characters(usize::MAX)); + + SkillLine::new(&beta, SkillEnvironmentRender::Omit) + .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)); let budget = SkillMetadataBudget::Characters(minimum_cost + 6); let rendered = build_available_skills_from_metadata(&[alpha, beta], budget) @@ -1056,9 +1129,9 @@ mod tests { let long_skill = make_skill_with_description("long-skill", SkillScope::Repo, &long_description); let empty_skill = make_skill_with_description("empty-skill", SkillScope::Repo, ""); - let minimum_cost = SkillLine::new(&long_skill) + let minimum_cost = SkillLine::new(&long_skill, SkillEnvironmentRender::Omit) .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)) - + SkillLine::new(&empty_skill) + + SkillLine::new(&empty_skill, SkillEnvironmentRender::Omit) .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)); let budget = SkillMetadataBudget::Characters(minimum_cost + 49); @@ -1084,8 +1157,8 @@ mod tests { let long_description = "a".repeat(1000); let long_skill = make_skill_with_description("long-skill", SkillScope::Repo, &long_description); - let minimum_cost = - SkillLine::new(&long_skill).minimum_cost(SkillMetadataBudget::Tokens(usize::MAX)); + let minimum_cost = SkillLine::new(&long_skill, SkillEnvironmentRender::Omit) + .minimum_cost(SkillMetadataBudget::Tokens(usize::MAX)); let budget = SkillMetadataBudget::Tokens(minimum_cost + 1); let rendered = build_available_skills_from_metadata(&[long_skill], budget) @@ -1101,9 +1174,10 @@ mod tests { fn budgeted_rendering_redistributes_unused_description_budget() { let short = make_skill_with_description("short-skill", SkillScope::Repo, "x"); let long = make_skill_with_description("long-skill", SkillScope::Repo, "abcdefghi"); - let minimum_cost = SkillLine::new(&short) + let minimum_cost = SkillLine::new(&short, SkillEnvironmentRender::Omit) .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)) - + SkillLine::new(&long).minimum_cost(SkillMetadataBudget::Characters(usize::MAX)); + + SkillLine::new(&long, SkillEnvironmentRender::Omit) + .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)); let budget = SkillMetadataBudget::Characters(minimum_cost + 11); let rendered = build_available_skills_from_metadata(&[short.clone(), long.clone()], budget) @@ -1127,10 +1201,14 @@ mod tests { let user = make_skill("user-skill", SkillScope::User); let repo = make_skill("repo-skill", SkillScope::Repo); let admin = make_skill("admin-skill", SkillScope::Admin); - let system_cost = SkillMetadataBudget::Characters(usize::MAX) - .cost(&format!("{}\n", SkillLine::new(&system).render_minimum())); - let admin_cost = SkillMetadataBudget::Characters(usize::MAX) - .cost(&format!("{}\n", SkillLine::new(&admin).render_minimum())); + let system_cost = SkillMetadataBudget::Characters(usize::MAX).cost(&format!( + "{}\n", + SkillLine::new(&system, SkillEnvironmentRender::Omit).render_minimum() + )); + let admin_cost = SkillMetadataBudget::Characters(usize::MAX).cost(&format!( + "{}\n", + SkillLine::new(&admin, SkillEnvironmentRender::Omit).render_minimum() + )); let budget = SkillMetadataBudget::Characters(system_cost + admin_cost); let rendered = build_available_skills_from_metadata(&[system, user, repo, admin], budget) @@ -1158,8 +1236,10 @@ mod tests { let mut oversized = make_skill("oversized-system-skill", SkillScope::System); oversized.description = "desc ".repeat(100); let repo = make_skill("repo-skill", SkillScope::Repo); - let repo_cost = SkillMetadataBudget::Characters(usize::MAX) - .cost(&format!("{}\n", SkillLine::new(&repo).render_full())); + let repo_cost = SkillMetadataBudget::Characters(usize::MAX).cost(&format!( + "{}\n", + SkillLine::new(&repo, SkillEnvironmentRender::Omit).render_full() + )); let budget = SkillMetadataBudget::Characters(repo_cost); let rendered = build_available_skills_from_metadata(&[oversized, repo], budget) @@ -1195,6 +1275,7 @@ mod tests { let rendered = build_available_skills( &outcome, SkillMetadataBudget::Characters(usize::MAX), + SkillEnvironmentRender::Omit, SkillRenderSideEffects::None, ) .expect("skills should render"); @@ -1218,7 +1299,8 @@ mod tests { let outcome = outcome_with_roots(skills.clone(), vec![root]); let absolute_minimum = skills.iter().fold(0usize, |cost, skill| { cost.saturating_add( - SkillLine::new(skill).minimum_cost(SkillMetadataBudget::Characters(usize::MAX)), + SkillLine::new(skill, SkillEnvironmentRender::Omit) + .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)), ) }); let plan = build_alias_plan( @@ -1229,8 +1311,12 @@ mod tests { .expect("alias plan should build"); let alias_minimum = skills.iter().fold(plan.table_cost, |cost, skill| { cost.saturating_add( - SkillLine::with_path(skill, render_skill_path_with_aliases(skill, &plan)) - .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)), + SkillLine::with_path( + skill, + render_skill_path_with_aliases(skill, &plan), + SkillEnvironmentRender::Omit, + ) + .minimum_cost(SkillMetadataBudget::Characters(usize::MAX)), ) }); assert!( @@ -1241,6 +1327,7 @@ mod tests { let rendered = build_available_skills( &outcome, SkillMetadataBudget::Characters(alias_minimum), + SkillEnvironmentRender::Omit, SkillRenderSideEffects::None, ) .expect("skills should render"); @@ -1264,6 +1351,51 @@ mod tests { assert!(rendered_text.contains("r0/skill-11/SKILL.md")); } + #[test] + fn multi_environment_rendering_qualifies_absolute_and_aliased_skill_lines() { + let root = test_path_buf("/tmp/repo/.agents/skills").abs(); + let mut skill = skill_with_path("gh-fix-ci", &root.join("gh-fix-ci/SKILL.md")); + skill.environment_id = "devbox".to_string(); + let outcome = outcome_with_roots(vec![skill.clone()], vec![root.clone()]); + + let absolute = build_available_skills( + &outcome, + SkillMetadataBudget::Characters(usize::MAX), + SkillEnvironmentRender::Include, + SkillRenderSideEffects::None, + ) + .expect("skills should render"); + assert_eq!( + absolute.skill_lines, + vec![format!( + "- gh-fix-ci: desc (env: devbox, file: {})", + normalized_path(&skill.path_to_skills_md) + )] + ); + + let plan = build_alias_plan( + &outcome, + &[skill.clone()], + SkillMetadataBudget::Characters(usize::MAX), + ) + .expect("alias plan should build"); + let aliased = build_aliased_available_skills( + &outcome, + &[skill], + SkillMetadataBudget::Characters(usize::MAX), + SkillEnvironmentRender::Include, + ) + .expect("skills should render"); + assert_eq!( + plan.aliases.skill_root_lines, + vec!["- `r0` = `/tmp/repo/.agents/skills`"] + ); + assert_eq!( + aliased.skill_lines, + vec!["- gh-fix-ci: desc (env: devbox, file: r0/gh-fix-ci/SKILL.md)"] + ); + } + #[test] fn outcome_rendering_uses_marketplace_root_for_single_skill_plugin_versions() { let github_root = @@ -1347,13 +1479,18 @@ mod tests { .expect("alias plan should build"); let alpha_cost = SkillMetadataBudget::Characters(usize::MAX).cost(&format!( "{}\n", - SkillLine::with_path(&alpha, render_skill_path_with_aliases(&alpha, &plan)) - .render_minimum() + SkillLine::with_path( + &alpha, + render_skill_path_with_aliases(&alpha, &plan), + SkillEnvironmentRender::Omit, + ) + .render_minimum() )); let rendered = build_aliased_available_skills( &outcome, &[alpha, beta], SkillMetadataBudget::Characters(plan.table_cost + alpha_cost), + SkillEnvironmentRender::Omit, ) .expect("skills should render"); @@ -1507,6 +1644,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 } } diff --git a/codex-rs/core/src/context/available_skills_instructions.rs b/codex-rs/core/src/context/available_skills_instructions.rs index e63d637677..0bec6bbef1 100644 --- a/codex-rs/core/src/context/available_skills_instructions.rs +++ b/codex-rs/core/src/context/available_skills_instructions.rs @@ -1,4 +1,5 @@ use codex_core_skills::AvailableSkills; +use codex_core_skills::SkillEnvironmentRender; use codex_core_skills::render_available_skills_body; use codex_protocol::protocol::SKILLS_INSTRUCTIONS_CLOSE_TAG; use codex_protocol::protocol::SKILLS_INSTRUCTIONS_OPEN_TAG; @@ -9,6 +10,7 @@ use super::ContextualUserFragment; pub(crate) struct AvailableSkillsInstructions { skill_root_lines: Vec, skill_lines: Vec, + environment_render: SkillEnvironmentRender, } impl From for AvailableSkillsInstructions { @@ -16,6 +18,7 @@ impl From for AvailableSkillsInstructions { Self { skill_root_lines: available_skills.skill_root_lines, skill_lines: available_skills.skill_lines, + environment_render: available_skills.environment_render, } } } @@ -34,6 +37,10 @@ impl ContextualUserFragment for AvailableSkillsInstructions { } fn body(&self) -> String { - render_available_skills_body(&self.skill_root_lines, &self.skill_lines) + render_available_skills_body( + &self.skill_root_lines, + &self.skill_lines, + self.environment_render, + ) } } diff --git a/codex-rs/core/src/session/mod.rs b/codex-rs/core/src/session/mod.rs index 8c535cd728..8270db5ac1 100644 --- a/codex-rs/core/src/session/mod.rs +++ b/codex-rs/core/src/session/mod.rs @@ -2744,6 +2744,11 @@ impl Session { let available_skills = build_available_skills( &turn_context.turn_skills.outcome, default_skill_metadata_budget(turn_context.model_info.context_window), + if turn_context.environments.turn_environments.len() > 1 { + crate::skills::render::SkillEnvironmentRender::Include + } else { + crate::skills::render::SkillEnvironmentRender::Omit + }, SkillRenderSideEffects::ThreadStart { session_telemetry: &self.services.session_telemetry, }, diff --git a/codex-rs/core/src/session/tests.rs b/codex-rs/core/src/session/tests.rs index 718983c0c2..52f63fab04 100644 --- a/codex-rs/core/src/session/tests.rs +++ b/codex-rs/core/src/session/tests.rs @@ -7255,7 +7255,11 @@ async fn build_initial_context_trims_skill_metadata_from_context_window_budget() interface: None, dependencies: None, policy: None, - path_to_skills_md: test_path_buf("/tmp/admin-skill/SKILL.md").abs(), + path_to_skills_md: test_path_buf("/tmp/admin-skill/SKILL.md").abs().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local( + test_path_buf("/tmp/admin-skill/SKILL.md").abs(), + ), + environment_id: "local".to_string(), scope: SkillScope::Admin, plugin_id: None, }, @@ -7266,7 +7270,11 @@ async fn build_initial_context_trims_skill_metadata_from_context_window_budget() interface: None, dependencies: None, policy: None, - path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs(), + path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local( + test_path_buf("/tmp/repo-skill/SKILL.md").abs(), + ), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }, @@ -7302,13 +7310,18 @@ fn emit_thread_start_skill_metrics_records_enabled_kept_and_truncated_values() { interface: None, dependencies: None, policy: None, - path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs(), + path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local( + test_path_buf("/tmp/repo-skill/SKILL.md").abs(), + ), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }]; let rendered = build_available_skills( &outcome, SkillMetadataBudget::Characters(1), + SkillEnvironmentRender::Omit, SkillRenderSideEffects::ThreadStart { session_telemetry: &session_telemetry, }, @@ -7347,7 +7360,11 @@ fn emit_thread_start_skill_metrics_records_description_truncated_chars_without_o interface: None, dependencies: None, policy: None, - path_to_skills_md: test_path_buf("/tmp/alpha-skill/SKILL.md").abs(), + path_to_skills_md: test_path_buf("/tmp/alpha-skill/SKILL.md").abs().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local( + test_path_buf("/tmp/alpha-skill/SKILL.md").abs(), + ), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }; @@ -7358,7 +7375,11 @@ fn emit_thread_start_skill_metrics_records_description_truncated_chars_without_o interface: None, dependencies: None, policy: None, - path_to_skills_md: test_path_buf("/tmp/beta-skill/SKILL.md").abs(), + path_to_skills_md: test_path_buf("/tmp/beta-skill/SKILL.md").abs().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local( + test_path_buf("/tmp/beta-skill/SKILL.md").abs(), + ), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }; @@ -7375,6 +7396,7 @@ fn emit_thread_start_skill_metrics_records_description_truncated_chars_without_o let rendered = build_available_skills( &outcome, SkillMetadataBudget::Characters(minimum_budget + 6), + SkillEnvironmentRender::Omit, SkillRenderSideEffects::ThreadStart { session_telemetry: &session_telemetry, }, @@ -7406,7 +7428,11 @@ async fn build_initial_context_emits_thread_start_skill_warning_on_repeated_buil interface: None, dependencies: None, policy: None, - path_to_skills_md: test_path_buf("/tmp/admin-skill/SKILL.md").abs(), + path_to_skills_md: test_path_buf("/tmp/admin-skill/SKILL.md").abs().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local( + test_path_buf("/tmp/admin-skill/SKILL.md").abs(), + ), + environment_id: "local".to_string(), scope: SkillScope::Admin, plugin_id: None, }, @@ -7417,7 +7443,11 @@ async fn build_initial_context_emits_thread_start_skill_warning_on_repeated_buil interface: None, dependencies: None, policy: None, - path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs(), + path_to_skills_md: test_path_buf("/tmp/repo-skill/SKILL.md").abs().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local( + test_path_buf("/tmp/repo-skill/SKILL.md").abs(), + ), + environment_id: "local".to_string(), scope: SkillScope::Repo, plugin_id: None, }, diff --git a/codex-rs/core/src/session/turn_context.rs b/codex-rs/core/src/session/turn_context.rs index 93c399cf6b..e6e487a20c 100644 --- a/codex-rs/core/src/session/turn_context.rs +++ b/codex-rs/core/src/session/turn_context.rs @@ -678,14 +678,21 @@ impl Session { &per_turn_config.to_models_manager_config(), ) .await; - let path_ref = primary_turn_environment.map(|turn_environment| { - crate::skills::EnvironmentPathRef::new( - turn_environment.environment.get_filesystem(), - turn_environment.cwd.clone(), + let skill_env_paths = turn_environments + .turn_environments + .iter() + .map( + |turn_environment| codex_core_skills::loader::SkillEnvironment { + environment_id: turn_environment.environment_id.clone(), + path: crate::skills::EnvironmentPathRef::new( + turn_environment.environment.get_filesystem(), + 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 + .collect::>(); + let skills_outcome = if !skill_env_paths.is_empty() { + // Workspace/repo skill roots use the selected turn environment paths above, while // user/system/plugin skill roots still read from the available local filesystem. let local_file_system = self .services @@ -699,9 +706,9 @@ impl Session { .plugins_for_config(&plugins_input) .await; let effective_skill_roots = plugin_outcome.effective_plugin_skill_roots(); - let skills_input = skills_load_input_from_config( + let skills_input = crate::skills::skills_load_input_from_environments( &per_turn_config, - path_ref, + skill_env_paths, local_file_system, effective_skill_roots, ); diff --git a/codex-rs/core/src/skills.rs b/codex-rs/core/src/skills.rs index 03e9180b9a..31d1278496 100644 --- a/codex-rs/core/src/skills.rs +++ b/codex-rs/core/src/skills.rs @@ -43,7 +43,25 @@ pub(crate) fn skills_load_input_from_config( effective_skill_roots: Vec, ) -> SkillsLoadInput { SkillsLoadInput::new( - env_path, + vec![codex_core_skills::loader::SkillEnvironment { + environment_id: codex_exec_server::LOCAL_ENVIRONMENT_ID.to_string(), + path: env_path, + }], + local_file_system, + effective_skill_roots, + config.config_layer_stack.clone(), + config.bundled_skills_enabled(), + ) +} + +pub(crate) fn skills_load_input_from_environments( + config: &Config, + env_paths: Vec, + local_file_system: Option>, + effective_skill_roots: Vec, +) -> SkillsLoadInput { + SkillsLoadInput::new( + env_paths, local_file_system, effective_skill_roots, config.config_layer_stack.clone(), diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index 721824ed61..283bf50095 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -6254,7 +6254,9 @@ mod tests { interface: None, dependencies: None, policy: None, - path_to_skills_md: skill_path.clone(), + path_to_skills_md: skill_path.clone().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(skill_path.clone()), + environment_id: "local".to_string(), scope: crate::test_support::skill_scope_user(), plugin_id: None, }])); @@ -6297,7 +6299,9 @@ mod tests { }), dependencies: None, policy: None, - path_to_skills_md: skill_path.clone(), + path_to_skills_md: skill_path.clone().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local(skill_path.clone()), + environment_id: "local".to_string(), scope: crate::test_support::skill_scope_repo(), plugin_id: None, }])); @@ -6389,7 +6393,13 @@ mod tests { }), dependencies: None, policy: None, - path_to_skills_md: test_path_buf("/tmp/repo/google-calendar/SKILL.md").abs(), + path_to_skills_md: test_path_buf("/tmp/repo/google-calendar/SKILL.md") + .abs() + .clone(), + source_path: codex_exec_server::EnvironmentPathRef::local( + test_path_buf("/tmp/repo/google-calendar/SKILL.md").abs(), + ), + environment_id: "local".to_string(), scope: crate::test_support::skill_scope_repo(), plugin_id: None, }])); diff --git a/codex-rs/tui/src/bottom_pane/mod.rs b/codex-rs/tui/src/bottom_pane/mod.rs index fa92914670..05e8bc192b 100644 --- a/codex-rs/tui/src/bottom_pane/mod.rs +++ b/codex-rs/tui/src/bottom_pane/mod.rs @@ -2576,7 +2576,11 @@ mod tests { interface: None, dependencies: None, policy: None, - path_to_skills_md: test_path_buf("/tmp/test-skill/SKILL.md").abs(), + path_to_skills_md: test_path_buf("/tmp/test-skill/SKILL.md").abs().clone(), + source_path: codex_exec_server::EnvironmentPathRef::local( + test_path_buf("/tmp/test-skill/SKILL.md").abs(), + ), + environment_id: "local".to_string(), scope: crate::test_support::skill_scope_user(), plugin_id: None, }]), diff --git a/codex-rs/tui/src/chatwidget/skills.rs b/codex-rs/tui/src/chatwidget/skills.rs index 687ce56416..67dd5cdd6c 100644 --- a/codex-rs/tui/src/chatwidget/skills.rs +++ b/codex-rs/tui/src/chatwidget/skills.rs @@ -241,7 +241,9 @@ fn protocol_skill_to_core(skill: &ProtocolSkillMetadata) -> Option