Lightweight coding agent that runs in your terminal
Rust
Improve external agent plugin migration for configured marketplaces (#18055)
alexsong-oai109b22a8d024
diff --git a/codex-rs/app-server/src/external_agent_config_api.rs b/codex-rs/app-server/src/external_agent_config_api.rsindex 3e20632db2..2f90a55a13 100644--- a/codex-rs/app-server/src/external_agent_config_api.rs+++ b/codex-rs/app-server/src/external_agent_config_api.rs@@ -37,6 +37,7 @@ impl ExternalAgentConfigApi {include_home: params.include_home,cwds: params.cwds,})+ .await.map_err(map_io_error)?;Ok(ExternalAgentConfigDetectResponse {diff --git a/codex-rs/core/src/external_agent_config.rs b/codex-rs/core/src/external_agent_config.rsindex 18305a6262..f0f4443a75 100644--- a/codex-rs/core/src/external_agent_config.rs+++ b/codex-rs/core/src/external_agent_config.rs@@ -1,8 +1,15 @@+use crate::config::Config;+use crate::config::ConfigBuilder;use crate::plugins::MarketplaceAddRequest;use crate::plugins::PluginId;use crate::plugins::PluginInstallRequest;use crate::plugins::PluginsManager;use crate::plugins::add_marketplace;+use crate::plugins::configured_plugins_from_stack;+use crate::plugins::find_marketplace_manifest_path;+use crate::plugins::parse_marketplace_source;+use codex_core_plugins::marketplace::MarketplacePluginInstallPolicy;+use codex_protocol::protocol::Product;use serde_json::Value as JsonValue;use std::collections::BTreeMap;use std::collections::HashSet;@@ -15,8 +22,8 @@ use toml::Value as TomlValue;const EXTERNAL_AGENT_CONFIG_DETECT_METRIC: &str = "codex.external_agent_config.detect";const EXTERNAL_AGENT_CONFIG_IMPORT_METRIC: &str = "codex.external_agent_config.import";-// Installed marketplace roots always expose their manifest at this relative path.-const INSTALLED_MARKETPLACE_MANIFEST_RELATIVE_PATH: &str = ".agents/plugins/marketplace.json";+const EXTERNAL_AGENT_DIR: &str = ".claude";+const EXTERNAL_AGENT_CONFIG_MD: &str = "CLAUDE.md";#[derive(Debug, Clone, PartialEq, Eq)]pub struct ExternalAgentConfigDetectOptions {@@ -83,20 +90,21 @@ impl ExternalAgentConfigService {}}- pub fn detect(+ pub async fn detect(&self,params: ExternalAgentConfigDetectOptions,) -> io::Result<Vec<ExternalAgentConfigMigrationItem>> {let mut items = Vec::new();if params.include_home {- self.detect_migrations(/*repo_root*/ None, &mut items)?;+ self.detect_migrations(/*repo_root*/ None, &mut items)+ .await?;}for cwd in params.cwds.as_deref().unwrap_or(&[]) {let Some(repo_root) = find_repo_root(Some(cwd))? else {continue;};- self.detect_migrations(Some(&repo_root), &mut items)?;+ self.detect_migrations(Some(&repo_root), &mut items).await?;}Ok(items)@@ -137,22 +145,11 @@ impl ExternalAgentConfigService {let cwd = migration_item.cwd;let details = migration_item.details;tokio::spawn(async move {- match service.import_plugins(cwd.as_deref(), details).await {- Ok(outcome) => {- tracing::info!(- succeeded_marketplaces = outcome.succeeded_marketplaces.len(),- succeeded_plugin_ids = outcome.succeeded_plugin_ids.len(),- failed_marketplaces = outcome.failed_marketplaces.len(),- failed_plugin_ids = outcome.failed_plugin_ids.len(),- "external agent config plugin import completed"- );- }- Err(err) => {- tracing::warn!(- error = %err,- "external agent config plugin import failed"- );- }+ if let Err(err) = service.import_plugins(cwd.as_deref(), details).await {+ tracing::warn!(+ error = %err,+ "external agent config plugin import failed"+ );}});emit_migration_metric(@@ -168,7 +165,7 @@ impl ExternalAgentConfigService {Ok(())}- fn detect_migrations(+ async fn detect_migrations(&self,repo_root: Option<&Path>,items: &mut Vec<ExternalAgentConfigMigrationItem>,@@ -176,7 +173,7 @@ impl ExternalAgentConfigService {let cwd = repo_root.map(Path::to_path_buf);let source_settings = repo_root.map_or_else(|| self.external_agent_home.join("settings.json"),- |repo_root| repo_root.join(".claude").join("settings.json"),+ |repo_root| repo_root.join(EXTERNAL_AGENT_DIR).join("settings.json"),);let settings = read_external_settings(&source_settings)?;let target_config = repo_root.map_or_else(@@ -219,16 +216,9 @@ impl ExternalAgentConfigService {}}- self.detect_plugin_migration(- source_settings.as_path(),- cwd.clone(),- settings.as_ref(),- items,- );-let source_skills = repo_root.map_or_else(|| self.external_agent_home.join("skills"),- |repo_root| repo_root.join(".claude").join("skills"),+ |repo_root| repo_root.join(EXTERNAL_AGENT_DIR).join("skills"),);let target_skills = repo_root.map_or_else(|| self.home_target_skills_dir(),@@ -239,7 +229,7 @@ impl ExternalAgentConfigService {items.push(ExternalAgentConfigMigrationItem {item_type: ExternalAgentConfigMigrationItemType::Skills,description: format!(- "Copy skill folders from {} to {}",+ "Migrate skills from {} to {}",source_skills.display(),target_skills.display()),@@ -256,7 +246,7 @@ impl ExternalAgentConfigService {let source_agents_md = if let Some(repo_root) = repo_root {find_repo_agents_md_source(repo_root)?} else {- let path = self.external_agent_home.join("CLAUDE.md");+ let path = self.external_agent_home.join(EXTERNAL_AGENT_CONFIG_MD);is_non_empty_text_file(&path)?.then_some(path)};let target_agents_md = repo_root.map_or_else(@@ -273,7 +263,7 @@ impl ExternalAgentConfigService {source_agents_md.display(),target_agents_md.display()),- cwd,+ cwd: cwd.clone(),details: None,});emit_migration_metric(@@ -283,6 +273,43 @@ impl ExternalAgentConfigService {);}+ if let Some(settings) = settings.as_ref() {+ match ConfigBuilder::default()+ .codex_home(self.codex_home.clone())+ .fallback_cwd(Some(self.codex_home.clone()))+ .build()+ .await+ {+ Ok(config) => {+ let configured_plugin_ids =+ configured_plugins_from_stack(&config.config_layer_stack)+ .into_keys()+ .collect::<HashSet<_>>();+ let configured_marketplace_plugins = configured_marketplace_plugins(+ &config,+ &PluginsManager::new(self.codex_home.clone()),+ )?;+ if let Some(item) = self.detect_plugin_migration(+ source_settings.as_path(),+ repo_root.unwrap_or(self.external_agent_home.as_path()),+ cwd.clone(),+ settings,+ &configured_plugin_ids,+ &configured_marketplace_plugins,+ ) {+ items.push(item);+ }+ }+ Err(err) => {+ tracing::warn!(+ error = %err,+ settings_path = %source_settings.display(),+ "skipping external agent plugin migration detection because config load failed"+ );+ }+ }+ }+Ok(())}@@ -296,25 +323,30 @@ impl ExternalAgentConfigService {fn detect_plugin_migration(&self,source_settings: &Path,+ source_root: &Path,cwd: Option<PathBuf>,- settings: Option<&JsonValue>,- items: &mut Vec<ExternalAgentConfigMigrationItem>,- ) {- let Some(plugin_details) = settings.and_then(extract_plugin_migration_details) else {- return;- };-- items.push(ExternalAgentConfigMigrationItem {- item_type: ExternalAgentConfigMigrationItemType::Plugins,- description: format!("Import enabled plugins from {}", source_settings.display()),- cwd,- details: Some(plugin_details),- });+ settings: &JsonValue,+ configured_plugin_ids: &HashSet<String>,+ configured_marketplace_plugins: &BTreeMap<String, HashSet<String>>,+ ) -> Option<ExternalAgentConfigMigrationItem> {+ let plugin_details = extract_plugin_migration_details(+ settings,+ source_root,+ configured_plugin_ids,+ configured_marketplace_plugins,+ )?;emit_migration_metric(EXTERNAL_AGENT_CONFIG_DETECT_METRIC,ExternalAgentConfigMigrationItemType::Plugins,/*skills_count*/ None,);++ Some(ExternalAgentConfigMigrationItem {+ item_type: ExternalAgentConfigMigrationItemType::Plugins,+ description: format!("Import enabled plugins from {}", source_settings.display()),+ cwd,+ details: Some(plugin_details),+ })}async fn import_plugins(@@ -336,8 +368,14 @@ impl ExternalAgentConfigService {.iter().map(|plugin_name| format!("{plugin_name}@{marketplace_name}")).collect::<Vec<_>>();- let import_source =- read_marketplace_import_source(cwd, &self.external_agent_home, &marketplace_name)?;+ let source_settings = cwd.map_or_else(+ || self.external_agent_home.join("settings.json"),+ |cwd| cwd.join(EXTERNAL_AGENT_DIR).join("settings.json"),+ );+ let source_root = cwd.unwrap_or(self.external_agent_home.as_path());+ let import_source = read_external_settings(&source_settings)?.and_then(|settings| {+ collect_marketplace_import_sources(&settings, source_root).remove(&marketplace_name)+ });let Some(import_source) = import_source else {outcome.failed_marketplaces.push(marketplace_name);outcome.failed_plugin_ids.extend(plugin_ids);@@ -351,12 +389,17 @@ impl ExternalAgentConfigService {let add_marketplace_outcome = add_marketplace(self.codex_home.clone(), request).await;let marketplace_path = match add_marketplace_outcome {Ok(add_marketplace_outcome) => {+ let Some(marketplace_path) = find_marketplace_manifest_path(+ add_marketplace_outcome.installed_root.as_path(),+ ) else {+ outcome.failed_marketplaces.push(marketplace_name);+ outcome.failed_plugin_ids.extend(plugin_ids);+ continue;+ };outcome.succeeded_marketplaces.push(marketplace_name.clone());- add_marketplace_outcome- .installed_root- .join(INSTALLED_MARKETPLACE_MANIFEST_RELATIVE_PATH)+ marketplace_path}Err(_) => {outcome.failed_marketplaces.push(marketplace_name);@@ -388,7 +431,7 @@ impl ExternalAgentConfigService {fn import_config(&self, cwd: Option<&Path>) -> io::Result<()> {let (source_settings, target_config) = if let Some(repo_root) = find_repo_root(cwd)? {(- repo_root.join(".claude").join("settings.json"),+ repo_root.join(EXTERNAL_AGENT_DIR).join("settings.json"),repo_root.join(".codex").join("config.toml"),)} else if cwd.is_some_and(|cwd| !cwd.as_os_str().is_empty()) {@@ -440,7 +483,7 @@ impl ExternalAgentConfigService {fn import_skills(&self, cwd: Option<&Path>) -> io::Result<usize> {let (source_skills, target_skills) = if let Some(repo_root) = find_repo_root(cwd)? {(- repo_root.join(".claude").join("skills"),+ repo_root.join(EXTERNAL_AGENT_DIR).join("skills"),repo_root.join(".agents").join("skills"),)} else if cwd.is_some_and(|cwd| !cwd.as_os_str().is_empty()) {@@ -487,7 +530,7 @@ impl ExternalAgentConfigService {return Ok(());} else {(- self.external_agent_home.join("CLAUDE.md"),+ self.external_agent_home.join(EXTERNAL_AGENT_CONFIG_MD),self.codex_home.join("AGENTS.md"),)};@@ -508,10 +551,10 @@ impl ExternalAgentConfigService {fn default_external_agent_home() -> PathBuf {if let Some(home) = std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE")) {- return PathBuf::from(home).join(".claude");+ return PathBuf::from(home).join(EXTERNAL_AGENT_DIR);}- PathBuf::from(".claude")+ PathBuf::from(EXTERNAL_AGENT_DIR)}fn read_external_settings(path: &Path) -> io::Result<Option<JsonValue>> {@@ -525,12 +568,37 @@ fn read_external_settings(path: &Path) -> io::Result<Option<JsonValue>> {Ok(Some(settings))}-fn extract_plugin_migration_details(settings: &JsonValue) -> Option<MigrationDetails> {+fn extract_plugin_migration_details(+ settings: &JsonValue,+ source_root: &Path,+ configured_plugin_ids: &HashSet<String>,+ configured_marketplace_plugins: &BTreeMap<String, HashSet<String>>,+) -> Option<MigrationDetails> {+ let loadable_marketplaces = collect_marketplace_import_sources(settings, source_root)+ .into_iter()+ .filter_map(|(marketplace_name, source)| {+ parse_marketplace_source(&source.source, source.ref_name)+ .ok()+ .map(|_| marketplace_name)+ })+ .collect::<HashSet<_>>();let mut plugins = BTreeMap::new();- for plugin_id in collect_enabled_plugins(settings) {+ for plugin_id in collect_enabled_plugins(settings)+ .into_iter()+ .filter(|plugin_id| !configured_plugin_ids.contains(plugin_id))+ {let Ok(plugin_id) = PluginId::parse(&plugin_id) else {continue;};+ if let Some(installable_plugins) =+ configured_marketplace_plugins.get(&plugin_id.marketplace_name)+ {+ if !installable_plugins.contains(&plugin_id.plugin_name) {+ continue;+ }+ } else if !loadable_marketplaces.contains(&plugin_id.marketplace_name) {+ continue;+ }let plugin_group = plugins.entry(plugin_id.marketplace_name.clone()).or_insert_with(|| PluginsMigration {@@ -579,8 +647,40 @@ fn collect_enabled_plugins(settings: &JsonValue) -> Vec<String> {.collect()}+fn configured_marketplace_plugins(+ config: &Config,+ plugins_manager: &PluginsManager,+) -> io::Result<BTreeMap<String, HashSet<String>>> {+ let marketplaces = plugins_manager+ .list_marketplaces_for_config(config, &[])+ .map_err(|err| {+ invalid_data_error(format!("failed to list configured marketplaces: {err}"))+ })?;+ let mut marketplace_plugins = BTreeMap::new();+ for marketplace in marketplaces.marketplaces {+ let plugins = marketplace+ .plugins+ .into_iter()+ .filter(|plugin| {+ plugin.policy.installation != MarketplacePluginInstallPolicy::NotAvailable+ })+ .filter(|plugin| {+ plugin+ .policy+ .products+ .as_deref()+ .is_none_or(|products| Product::Codex.matches_product_restriction(products))+ })+ .map(|plugin| plugin.name)+ .collect::<HashSet<_>>();+ marketplace_plugins.insert(marketplace.name, plugins);+ }+ Ok(marketplace_plugins)+}+fn collect_marketplace_import_sources(settings: &JsonValue,+ source_root: &Path,) -> BTreeMap<String, MarketplaceImportSource> {let Some(extra_known_marketplaces) = settings.as_object()@@ -611,6 +711,7 @@ fn collect_marketplace_import_sources(if source.is_empty() {return None;}+ let source = resolve_external_marketplace_source(&source, source_root);let ref_name = source_fields.get("ref")@@ -631,20 +732,16 @@ struct MarketplaceImportSource {ref_name: Option<String>,}-fn read_marketplace_import_source(- cwd: Option<&Path>,- external_agent_home: &Path,- marketplace_name: &str,-) -> io::Result<Option<MarketplaceImportSource>> {- let source_settings = cwd.map_or_else(- || external_agent_home.join("settings.json"),- |cwd| cwd.join(".claude").join("settings.json"),- );- let Some(settings) = read_external_settings(&source_settings)? else {- return Ok(None);- };+fn resolve_external_marketplace_source(source: &str, source_root: &Path) -> String {+ if !looks_like_relative_local_path(source) {+ return source.to_string();+ }- Ok(collect_marketplace_import_sources(&settings).remove(marketplace_name))+ source_root.join(source).display().to_string()+}++fn looks_like_relative_local_path(source: &str) -> bool {+ source.starts_with("./") || source.starts_with("../") || source == "." || source == ".."}fn find_repo_root(cwd: Option<&Path>) -> io::Result<Option<PathBuf>> {@@ -729,8 +826,10 @@ fn is_non_empty_text_file(path: &Path) -> io::Result<bool> {fn find_repo_agents_md_source(repo_root: &Path) -> io::Result<Option<PathBuf>> {for candidate in [- repo_root.join("CLAUDE.md"),- repo_root.join(".claude").join("CLAUDE.md"),+ repo_root.join(EXTERNAL_AGENT_CONFIG_MD),+ repo_root+ .join(EXTERNAL_AGENT_DIR)+ .join(EXTERNAL_AGENT_CONFIG_MD),] {if is_non_empty_text_file(&candidate)? {return Ok(Some(candidate));@@ -779,7 +878,11 @@ fn rewrite_and_copy_text_file(source: &Path, target: &Path) -> io::Result<()> {}fn rewrite_external_agent_terms(content: &str) -> String {- let mut rewritten = replace_case_insensitive_with_boundaries(content, "claude.md", "AGENTS.md");+ let mut rewritten = replace_case_insensitive_with_boundaries(+ content,+ &EXTERNAL_AGENT_CONFIG_MD.to_ascii_lowercase(),+ "AGENTS.md",+ );for from in ["claude code","claude-code",diff --git a/codex-rs/core/src/external_agent_config_tests.rs b/codex-rs/core/src/external_agent_config_tests.rsindex f2afab0170..f01a40e3d2 100644--- a/codex-rs/core/src/external_agent_config_tests.rs+++ b/codex-rs/core/src/external_agent_config_tests.rs@@ -5,13 +5,16 @@ use tempfile::TempDir;fn fixture_paths() -> (TempDir, PathBuf, PathBuf) {let root = TempDir::new().expect("create tempdir");- let claude_home = root.path().join(".claude");+ let external_agent_home = root.path().join(".claude");let codex_home = root.path().join(".codex");- (root, claude_home, codex_home)+ (root, external_agent_home, codex_home)}-fn service_for_paths(claude_home: PathBuf, codex_home: PathBuf) -> ExternalAgentConfigService {- ExternalAgentConfigService::new_for_test(codex_home, claude_home)+fn service_for_paths(+ external_agent_home: PathBuf,+ codex_home: PathBuf,+) -> ExternalAgentConfigService {+ ExternalAgentConfigService::new_for_test(codex_home, external_agent_home)}fn github_plugin_details() -> MigrationDetails {@@ -23,26 +26,28 @@ fn github_plugin_details() -> MigrationDetails {}}-#[test]-fn detect_home_lists_config_skills_and_agents_md() {- let (_root, claude_home, codex_home) = fixture_paths();+#[tokio::test]+async fn detect_home_lists_config_skills_and_agents_md() {+ let (_root, external_agent_home, codex_home) = fixture_paths();let agents_skills = codex_home.parent().map(|parent| parent.join(".agents").join("skills")).unwrap_or_else(|| PathBuf::from(".agents").join("skills"));- fs::create_dir_all(claude_home.join("skills").join("skill-a")).expect("create skills");- fs::write(claude_home.join("CLAUDE.md"), "claude rules").expect("write claude md");+ fs::create_dir_all(external_agent_home.join("skills").join("skill-a")).expect("create skills");+ fs::write(external_agent_home.join("CLAUDE.md"), "claude rules")+ .expect("write external agent md");fs::write(- claude_home.join("settings.json"),+ external_agent_home.join("settings.json"),r#"{"model":"claude","env":{"FOO":"bar"}}"#,).expect("write settings");- let items = service_for_paths(claude_home.clone(), codex_home.clone())+ let items = service_for_paths(external_agent_home.clone(), codex_home.clone()).detect(ExternalAgentConfigDetectOptions {include_home: true,cwds: None,})+ .await.expect("detect");let expected = vec![@@ -50,7 +55,7 @@ fn detect_home_lists_config_skills_and_agents_md() {item_type: ExternalAgentConfigMigrationItemType::Config,description: format!("Migrate {} into {}",- claude_home.join("settings.json").display(),+ external_agent_home.join("settings.json").display(),codex_home.join("config.toml").display()),cwd: None,@@ -59,8 +64,8 @@ fn detect_home_lists_config_skills_and_agents_md() {ExternalAgentConfigMigrationItem {item_type: ExternalAgentConfigMigrationItemType::Skills,description: format!(- "Copy skill folders from {} to {}",- claude_home.join("skills").display(),+ "Migrate skills from {} to {}",+ external_agent_home.join("skills").display(),agents_skills.display()),cwd: None,@@ -70,7 +75,7 @@ fn detect_home_lists_config_skills_and_agents_md() {item_type: ExternalAgentConfigMigrationItemType::AgentsMd,description: format!("Import {} to {}",- claude_home.join("CLAUDE.md").display(),+ external_agent_home.join("CLAUDE.md").display(),codex_home.join("AGENTS.md").display()),cwd: None,@@ -81,8 +86,8 @@ fn detect_home_lists_config_skills_and_agents_md() {assert_eq!(items, expected);}-#[test]-fn detect_repo_lists_agents_md_for_each_cwd() {+#[tokio::test]+async fn detect_repo_lists_agents_md_for_each_cwd() {let root = TempDir::new().expect("create tempdir");let repo_root = root.path().join("repo");let nested = repo_root.join("nested").join("child");@@ -95,6 +100,7 @@ fn detect_repo_lists_agents_md_for_each_cwd() {include_home: false,cwds: Some(vec![nested, repo_root.clone()]),})+ .await.expect("detect");let expected = vec![@@ -123,27 +129,110 @@ fn detect_repo_lists_agents_md_for_each_cwd() {assert_eq!(items, expected);}+#[tokio::test]+async fn detect_repo_still_reports_non_plugin_items_when_home_config_is_invalid() {+ let root = TempDir::new().expect("create tempdir");+ let repo_root = root.path().join("repo");+ let codex_home = root.path().join(".codex");+ fs::create_dir_all(repo_root.join(".git")).expect("create git dir");+ fs::create_dir_all(repo_root.join(".claude").join("skills").join("skill-a"))+ .expect("create repo skills");+ fs::create_dir_all(&codex_home).expect("create codex home");+ fs::write(codex_home.join("config.toml"), "this is not valid = [toml")+ .expect("write invalid codex config");+ fs::write(+ repo_root.join(".claude").join("settings.json"),+ r#"{"env":{"FOO":"bar"}}"#,+ )+ .expect("write settings");+ fs::write(+ repo_root+ .join(".claude")+ .join("skills")+ .join("skill-a")+ .join("SKILL.md"),+ "Use Claude Code and CLAUDE utilities.",+ )+ .expect("write skill");+ fs::write(+ repo_root.join(".claude").join("CLAUDE.md"),+ "Claude code guidance",+ )+ .expect("write agents");++ let items = service_for_paths(root.path().join(".claude"), codex_home)+ .detect(ExternalAgentConfigDetectOptions {+ include_home: false,+ cwds: Some(vec![repo_root.clone()]),+ })+ .await+ .expect("detect");++ assert_eq!(+ items,+ vec![+ ExternalAgentConfigMigrationItem {+ item_type: ExternalAgentConfigMigrationItemType::Config,+ description: format!(+ "Migrate {} into {}",+ repo_root.join(".claude").join("settings.json").display(),+ repo_root.join(".codex").join("config.toml").display()+ ),+ cwd: Some(repo_root.clone()),+ details: None,+ },+ ExternalAgentConfigMigrationItem {+ item_type: ExternalAgentConfigMigrationItemType::Skills,+ description: format!(+ "Migrate skills from {} to {}",+ repo_root.join(".claude").join("skills").display(),+ repo_root.join(".agents").join("skills").display()+ ),+ cwd: Some(repo_root.clone()),+ details: None,+ },+ ExternalAgentConfigMigrationItem {+ item_type: ExternalAgentConfigMigrationItemType::AgentsMd,+ description: format!(+ "Import {} to {}",+ repo_root.join(".claude").join("CLAUDE.md").display(),+ repo_root.join("AGENTS.md").display(),+ ),+ cwd: Some(repo_root),+ details: None,+ },+ ]+ );+}+#[tokio::test]async fn import_home_migrates_supported_config_fields_skills_and_agents_md() {- let (_root, claude_home, codex_home) = fixture_paths();+ let (_root, external_agent_home, codex_home) = fixture_paths();let agents_skills = codex_home.parent().map(|parent| parent.join(".agents").join("skills")).unwrap_or_else(|| PathBuf::from(".agents").join("skills"));- fs::create_dir_all(claude_home.join("skills").join("skill-a")).expect("create skills");+ fs::create_dir_all(external_agent_home.join("skills").join("skill-a")).expect("create skills");fs::write(- claude_home.join("settings.json"),+ external_agent_home.join("settings.json"),r#"{"model":"claude","permissions":{"ask":["git push"]},"env":{"FOO":"bar","CI":false,"MAX_RETRIES":3,"MY_TEAM":"codex","IGNORED":null,"LIST":["a","b"],"MAP":{"x":1}},"sandbox":{"enabled":true,"network":{"allowLocalBinding":true}}}"#,).expect("write settings");fs::write(- claude_home.join("skills").join("skill-a").join("SKILL.md"),+ external_agent_home+ .join("skills")+ .join("skill-a")+ .join("SKILL.md"),"Use Claude Code and CLAUDE utilities.",).expect("write skill");- fs::write(claude_home.join("CLAUDE.md"), "Claude code guidance").expect("write agents");+ fs::write(+ external_agent_home.join("CLAUDE.md"),+ "Claude code guidance",+ )+ .expect("write agents");- service_for_paths(claude_home, codex_home.clone())+ service_for_paths(external_agent_home, codex_home.clone()).import(vec![ExternalAgentConfigMigrationItem {item_type: ExternalAgentConfigMigrationItemType::AgentsMd,@@ -185,15 +274,15 @@ async fn import_home_migrates_supported_config_fields_skills_and_agents_md() {#[tokio::test]async fn import_home_skips_empty_config_migration() {- let (_root, claude_home, codex_home) = fixture_paths();- fs::create_dir_all(&claude_home).expect("create claude home");+ let (_root, external_agent_home, codex_home) = fixture_paths();+ fs::create_dir_all(&external_agent_home).expect("create external agent home");fs::write(- claude_home.join("settings.json"),+ external_agent_home.join("settings.json"),r#"{"model":"claude","sandbox":{"enabled":false}}"#,).expect("write settings");- service_for_paths(claude_home, codex_home.clone())+ service_for_paths(external_agent_home, codex_home.clone()).import(vec![ExternalAgentConfigMigrationItem {item_type: ExternalAgentConfigMigrationItemType::Config,description: String::new(),@@ -206,13 +295,13 @@ async fn import_home_skips_empty_config_migration() {assert!(!codex_home.join("config.toml").exists());}-#[test]-fn detect_home_skips_config_when_target_already_has_supported_fields() {- let (_root, claude_home, codex_home) = fixture_paths();- fs::create_dir_all(&claude_home).expect("create claude home");+#[tokio::test]+async fn detect_home_skips_config_when_target_already_has_supported_fields() {+ let (_root, external_agent_home, codex_home) = fixture_paths();+ fs::create_dir_all(&external_agent_home).expect("create external agent home");fs::create_dir_all(&codex_home).expect("create codex home");fs::write(- claude_home.join("settings.json"),+ external_agent_home.join("settings.json"),r#"{"env":{"FOO":"bar"},"sandbox":{"enabled":true}}"#,).expect("write settings");@@ -230,31 +319,33 @@ fn detect_home_skips_config_when_target_already_has_supported_fields() {).expect("write config");- let items = service_for_paths(claude_home, codex_home)+ let items = service_for_paths(external_agent_home, codex_home).detect(ExternalAgentConfigDetectOptions {include_home: true,cwds: None,})+ .await.expect("detect");assert_eq!(items, Vec::<ExternalAgentConfigMigrationItem>::new());}-#[test]-fn detect_home_skips_skills_when_all_skill_directories_exist() {- let (_root, claude_home, codex_home) = fixture_paths();+#[tokio::test]+async fn detect_home_skips_skills_when_all_skill_directories_exist() {+ let (_root, external_agent_home, codex_home) = fixture_paths();let agents_skills = codex_home.parent().map(|parent| parent.join(".agents").join("skills")).unwrap_or_else(|| PathBuf::from(".agents").join("skills"));- fs::create_dir_all(claude_home.join("skills").join("skill-a")).expect("create source");+ fs::create_dir_all(external_agent_home.join("skills").join("skill-a")).expect("create source");fs::create_dir_all(agents_skills.join("skill-a")).expect("create target");- let items = service_for_paths(claude_home, codex_home)+ let items = service_for_paths(external_agent_home, codex_home).detect(ExternalAgentConfigDetectOptions {include_home: true,cwds: None,})+ .await.expect("detect");assert_eq!(items, Vec::<ExternalAgentConfigMigrationItem>::new());@@ -332,8 +423,8 @@ async fn import_repo_agents_md_overwrites_empty_targets() {);}-#[test]-fn detect_repo_prefers_non_empty_dot_claude_agents_source() {+#[tokio::test]+async fn detect_repo_prefers_non_empty_external_agent_agents_source() {let root = TempDir::new().expect("create tempdir");let repo_root = root.path().join("repo");fs::create_dir_all(repo_root.join(".git")).expect("create git");@@ -350,6 +441,7 @@ fn detect_repo_prefers_non_empty_dot_claude_agents_source() {include_home: false,cwds: Some(vec![repo_root.clone()]),})+ .await.expect("detect");assert_eq!(@@ -368,7 +460,7 @@ fn detect_repo_prefers_non_empty_dot_claude_agents_source() {}#[tokio::test]-async fn import_repo_uses_non_empty_dot_claude_agents_source() {+async fn import_repo_uses_non_empty_external_agent_agents_source() {let root = TempDir::new().expect("create tempdir");let repo_root = root.path().join("repo");fs::create_dir_all(repo_root.join(".git")).expect("create git");@@ -407,27 +499,33 @@ fn migration_metric_tags_for_skills_include_skills_count() {);}-#[test]-fn detect_home_lists_enabled_plugins_from_settings() {- let (_root, claude_home, codex_home) = fixture_paths();- fs::create_dir_all(&claude_home).expect("create claude home");+#[tokio::test]+async fn detect_home_lists_enabled_plugins_from_settings() {+ let (_root, external_agent_home, codex_home) = fixture_paths();+ fs::create_dir_all(&external_agent_home).expect("create external agent home");fs::write(- claude_home.join("settings.json"),+ external_agent_home.join("settings.json"),r#"{"enabledPlugins": {"formatter@acme-tools": true,"deployer@acme-tools": true,"analyzer@security-plugins": false+ },+ "extraKnownMarketplaces": {+ "acme-tools": {+ "source": "acme-corp/claude-plugins"+ }}}"#,).expect("write settings");- let items = service_for_paths(claude_home.clone(), codex_home)+ let items = service_for_paths(external_agent_home.clone(), codex_home).detect(ExternalAgentConfigDetectOptions {include_home: true,cwds: None,})+ .await.expect("detect");assert_eq!(@@ -436,7 +534,7 @@ fn detect_home_lists_enabled_plugins_from_settings() {item_type: ExternalAgentConfigMigrationItemType::Plugins,description: format!("Import enabled plugins from {}",- claude_home.join("settings.json").display()+ external_agent_home.join("settings.json").display()),cwd: None,details: Some(MigrationDetails {@@ -449,11 +547,156 @@ fn detect_home_lists_enabled_plugins_from_settings() {);}+#[tokio::test]+async fn detect_repo_skips_plugins_that_are_already_configured_in_codex() {+ let root = TempDir::new().expect("create tempdir");+ let external_agent_home = root.path().join(".claude");+ let codex_home = root.path().join(".codex");+ let repo_root = root.path().join("repo");+ fs::create_dir_all(repo_root.join(".git")).expect("create git dir");+ fs::create_dir_all(repo_root.join(".claude")).expect("create repo external agent dir");+ fs::create_dir_all(&codex_home).expect("create codex home");+ fs::write(+ repo_root.join(".claude").join("settings.json"),+ r#"{+ "enabledPlugins": {+ "formatter@acme-tools": true,+ "deployer@acme-tools": true+ },+ "extraKnownMarketplaces": {+ "acme-tools": {+ "source": "acme-corp/claude-plugins"+ }+ }+ }"#,+ )+ .expect("write repo settings");+ fs::write(+ codex_home.join("config.toml"),+ r#"+[plugins."formatter@acme-tools"]+enabled = true+"#,+ )+ .expect("write codex config");++ let items = service_for_paths(external_agent_home, codex_home)+ .detect(ExternalAgentConfigDetectOptions {+ include_home: false,+ cwds: Some(vec![repo_root.clone()]),+ })+ .await+ .expect("detect");++ assert_eq!(+ items,+ vec![ExternalAgentConfigMigrationItem {+ item_type: ExternalAgentConfigMigrationItemType::Plugins,+ description: format!(+ "Import enabled plugins from {}",+ repo_root.join(".claude").join("settings.json").display()+ ),+ cwd: Some(repo_root),+ details: Some(MigrationDetails {+ plugins: vec![PluginsMigration {+ marketplace_name: "acme-tools".to_string(),+ plugin_names: vec!["deployer".to_string()],+ }],+ }),+ }]+ );+}++#[tokio::test]+async fn detect_repo_skips_plugins_that_are_disabled_in_codex() {+ let root = TempDir::new().expect("create tempdir");+ let external_agent_home = root.path().join(".claude");+ let codex_home = root.path().join(".codex");+ let repo_root = root.path().join("repo");+ fs::create_dir_all(repo_root.join(".git")).expect("create git dir");+ fs::create_dir_all(repo_root.join(".claude")).expect("create repo external agent dir");+ fs::create_dir_all(&codex_home).expect("create codex home");+ fs::write(+ repo_root.join(".claude").join("settings.json"),+ r#"{+ "enabledPlugins": {+ "formatter@acme-tools": true+ },+ "extraKnownMarketplaces": {+ "acme-tools": {+ "source": "acme-corp/claude-plugins"+ }+ }+ }"#,+ )+ .expect("write repo settings");+ fs::write(+ codex_home.join("config.toml"),+ r#"+[plugins."formatter@acme-tools"]+enabled = false+"#,+ )+ .expect("write codex config");++ let items = service_for_paths(external_agent_home, codex_home)+ .detect(ExternalAgentConfigDetectOptions {+ include_home: false,+ cwds: Some(vec![repo_root]),+ })+ .await+ .expect("detect");++ assert_eq!(items, Vec::<ExternalAgentConfigMigrationItem>::new());+}++#[tokio::test]+async fn detect_repo_skips_plugins_without_explicit_enabled_in_codex() {+ let root = TempDir::new().expect("create tempdir");+ let external_agent_home = root.path().join(".claude");+ let codex_home = root.path().join(".codex");+ let repo_root = root.path().join("repo");+ fs::create_dir_all(repo_root.join(".git")).expect("create git dir");+ fs::create_dir_all(repo_root.join(".claude")).expect("create repo external agent dir");+ fs::create_dir_all(&codex_home).expect("create codex home");+ fs::write(+ repo_root.join(".claude").join("settings.json"),+ r#"{+ "enabledPlugins": {+ "formatter@acme-tools": true+ },+ "extraKnownMarketplaces": {+ "acme-tools": {+ "source": "acme-corp/claude-plugins"+ }+ }+ }"#,+ )+ .expect("write repo settings");+ fs::write(+ codex_home.join("config.toml"),+ r#"+[plugins."formatter@acme-tools"]+"#,+ )+ .expect("write codex config");++ let items = service_for_paths(external_agent_home, codex_home)+ .detect(ExternalAgentConfigDetectOptions {+ include_home: false,+ cwds: Some(vec![repo_root]),+ })+ .await+ .expect("detect");++ assert_eq!(items, Vec::<ExternalAgentConfigMigrationItem>::new());+}+#[tokio::test]async fn import_plugins_requires_details() {- let (_root, claude_home, codex_home) = fixture_paths();+ let (_root, external_agent_home, codex_home) = fixture_paths();- let err = service_for_paths(claude_home, codex_home)+ let err = service_for_paths(external_agent_home, codex_home).import_plugins(/*cwd*/ None, /*details*/ None).await.expect_err("expected missing details error");@@ -463,76 +706,316 @@ async fn import_plugins_requires_details() {}#[tokio::test]-async fn import_plugins_requires_source_marketplace_details() {- let (_root, claude_home, codex_home) = fixture_paths();- fs::create_dir_all(&claude_home).expect("create claude home");+async fn detect_repo_does_not_skip_plugins_only_configured_in_project_codex() {+ let root = TempDir::new().expect("create tempdir");+ let external_agent_home = root.path().join(".claude");+ let codex_home = root.path().join(".codex");+ let repo_root = root.path().join("repo");+ fs::create_dir_all(repo_root.join(".git")).expect("create git dir");+ fs::create_dir_all(repo_root.join(".claude")).expect("create repo external agent dir");+ fs::create_dir_all(repo_root.join(".codex")).expect("create repo codex dir");+ fs::create_dir_all(&codex_home).expect("create codex home");fs::write(- claude_home.join("settings.json"),+ repo_root.join(".claude").join("settings.json"),r#"{"enabledPlugins": {"formatter@acme-tools": true},"extraKnownMarketplaces": {"acme-tools": {- "source": "github",- "repo": "acme-corp/claude-plugins"+ "source": "acme-corp/claude-plugins"}}}"#,)- .expect("write settings");+ .expect("write repo settings");+ fs::write(+ repo_root.join(".codex").join("config.toml"),+ r#"+[plugins."formatter@acme-tools"]+enabled = true+"#,+ )+ .expect("write project codex config");- let outcome = service_for_paths(claude_home, codex_home)- .import_plugins(- /*cwd*/ None,- Some(MigrationDetails {+ let items = service_for_paths(external_agent_home, codex_home)+ .detect(ExternalAgentConfigDetectOptions {+ include_home: false,+ cwds: Some(vec![repo_root.clone()]),+ })+ .await+ .expect("detect");++ assert_eq!(+ items,+ vec![ExternalAgentConfigMigrationItem {+ item_type: ExternalAgentConfigMigrationItemType::Plugins,+ description: format!(+ "Import enabled plugins from {}",+ repo_root.join(".claude").join("settings.json").display()+ ),+ cwd: Some(repo_root),+ details: Some(MigrationDetails {plugins: vec![PluginsMigration {- marketplace_name: "other-tools".to_string(),- plugin_names: github_plugin_details().plugins[0].plugin_names.clone(),+ marketplace_name: "acme-tools".to_string(),+ plugin_names: vec!["formatter".to_string()],}],}),- )+ }]+ );+}++#[tokio::test]+async fn detect_home_skips_plugins_without_marketplace_source() {+ let (_root, external_agent_home, codex_home) = fixture_paths();+ fs::create_dir_all(&external_agent_home).expect("create external agent home");+ fs::write(+ external_agent_home.join("settings.json"),+ r#"{+ "enabledPlugins": {+ "formatter@acme-tools": true+ }+ }"#,+ )+ .expect("write settings");++ let items = service_for_paths(external_agent_home, codex_home)+ .detect(ExternalAgentConfigDetectOptions {+ include_home: true,+ cwds: None,+ }).await- .expect("import plugins");+ .expect("detect");- assert_eq!(- outcome,- PluginImportOutcome {- succeeded_marketplaces: Vec::new(),- succeeded_plugin_ids: Vec::new(),- failed_marketplaces: vec!["other-tools".to_string()],- failed_plugin_ids: vec!["formatter@other-tools".to_string()],- }- );+ assert_eq!(items, Vec::<ExternalAgentConfigMigrationItem>::new());}#[tokio::test]-async fn import_plugins_defers_marketplace_source_validation_to_add_marketplace() {- let (_root, claude_home, codex_home) = fixture_paths();- fs::create_dir_all(&claude_home).expect("create claude home");+async fn detect_home_skips_plugins_with_invalid_marketplace_source() {+ let (_root, external_agent_home, codex_home) = fixture_paths();+ fs::create_dir_all(&external_agent_home).expect("create external agent home");fs::write(- claude_home.join("settings.json"),+ external_agent_home.join("settings.json"),r#"{"enabledPlugins": {"formatter@acme-tools": true},"extraKnownMarketplaces": {"acme-tools": {- "source": "local",- "path": "./external_plugins/acme-tools"+ "source": "github"}}}"#,).expect("write settings");- let outcome = service_for_paths(claude_home, codex_home)- .import_plugins(/*cwd*/ None, Some(github_plugin_details()))+ let items = service_for_paths(external_agent_home, codex_home)+ .detect(ExternalAgentConfigDetectOptions {+ include_home: true,+ cwds: None,+ }).await- .expect("import plugins");+ .expect("detect");- assert_eq!(- outcome,+ assert_eq!(items, Vec::<ExternalAgentConfigMigrationItem>::new());+}++#[tokio::test]+async fn detect_repo_filters_plugins_against_installed_marketplace() {+ let root = TempDir::new().expect("create tempdir");+ let external_agent_home = root.path().join(".claude");+ let codex_home = root.path().join(".codex");+ let repo_root = root.path().join("repo");+ let marketplace_root = codex_home.join(".tmp").join("marketplaces").join("debug");+ fs::create_dir_all(repo_root.join(".git")).expect("create git dir");+ fs::create_dir_all(repo_root.join(".claude")).expect("create repo external agent dir");+ fs::create_dir_all(marketplace_root.join(".agents").join("plugins"))+ .expect("create marketplace manifest dir");+ fs::create_dir_all(+ marketplace_root+ .join("plugins")+ .join("sample")+ .join(".codex-plugin"),+ )+ .expect("create sample plugin");+ fs::create_dir_all(+ marketplace_root+ .join("plugins")+ .join("available")+ .join(".codex-plugin"),+ )+ .expect("create available plugin");+ fs::write(+ repo_root.join(".claude").join("settings.json"),+ r#"{+ "enabledPlugins": {+ "sample@debug": true,+ "available@debug": true,+ "missing@debug": true+ },+ "extraKnownMarketplaces": {+ "debug": {+ "source": "owner/debug-marketplace"+ }+ }+ }"#,+ )+ .expect("write repo settings");+ fs::write(+ codex_home.join("config.toml"),+ r#"+[marketplaces.debug]+source_type = "git"+source = "owner/debug-marketplace"+"#,+ )+ .expect("write codex config");+ fs::write(+ marketplace_root+ .join(".agents")+ .join("plugins")+ .join("marketplace.json"),+ r#"{+ "name": "debug",+ "plugins": [+ {+ "name": "sample",+ "source": {+ "source": "local",+ "path": "./plugins/sample"+ },+ "policy": {+ "installation": "NOT_AVAILABLE"+ }+ },+ {+ "name": "available",+ "source": {+ "source": "local",+ "path": "./plugins/available"+ }+ }+ ]+}"#,+ )+ .expect("write marketplace manifest");+ fs::write(+ marketplace_root+ .join("plugins")+ .join("sample")+ .join(".codex-plugin")+ .join("plugin.json"),+ r#"{"name":"sample"}"#,+ )+ .expect("write sample plugin manifest");+ fs::write(+ marketplace_root+ .join("plugins")+ .join("available")+ .join(".codex-plugin")+ .join("plugin.json"),+ r#"{"name":"available"}"#,+ )+ .expect("write available plugin manifest");++ let items = service_for_paths(external_agent_home, codex_home)+ .detect(ExternalAgentConfigDetectOptions {+ include_home: false,+ cwds: Some(vec![repo_root.clone()]),+ })+ .await+ .expect("detect");++ assert_eq!(+ items,+ vec![ExternalAgentConfigMigrationItem {+ item_type: ExternalAgentConfigMigrationItemType::Plugins,+ description: format!(+ "Import enabled plugins from {}",+ repo_root.join(".claude").join("settings.json").display()+ ),+ cwd: Some(repo_root),+ details: Some(MigrationDetails {+ plugins: vec![PluginsMigration {+ marketplace_name: "debug".to_string(),+ plugin_names: vec!["available".to_string()],+ }],+ }),+ }]+ );+}++#[tokio::test]+async fn import_plugins_requires_source_marketplace_details() {+ let (_root, external_agent_home, codex_home) = fixture_paths();+ fs::create_dir_all(&external_agent_home).expect("create external agent home");+ fs::write(+ external_agent_home.join("settings.json"),+ r#"{+ "enabledPlugins": {+ "formatter@acme-tools": true+ },+ "extraKnownMarketplaces": {+ "acme-tools": {+ "source": "github",+ "repo": "acme-corp/claude-plugins"+ }+ }+ }"#,+ )+ .expect("write settings");++ let outcome = service_for_paths(external_agent_home, codex_home)+ .import_plugins(+ /*cwd*/ None,+ Some(MigrationDetails {+ plugins: vec![PluginsMigration {+ marketplace_name: "other-tools".to_string(),+ plugin_names: github_plugin_details().plugins[0].plugin_names.clone(),+ }],+ }),+ )+ .await+ .expect("import plugins");++ assert_eq!(+ outcome,+ PluginImportOutcome {+ succeeded_marketplaces: Vec::new(),+ succeeded_plugin_ids: Vec::new(),+ failed_marketplaces: vec!["other-tools".to_string()],+ failed_plugin_ids: vec!["formatter@other-tools".to_string()],+ }+ );+}++#[tokio::test]+async fn import_plugins_defers_marketplace_source_validation_to_add_marketplace() {+ let (_root, external_agent_home, codex_home) = fixture_paths();+ fs::create_dir_all(&external_agent_home).expect("create external agent home");+ fs::write(+ external_agent_home.join("settings.json"),+ r#"{+ "enabledPlugins": {+ "formatter@acme-tools": true+ },+ "extraKnownMarketplaces": {+ "acme-tools": {+ "source": "local",+ "path": "./external_plugins/acme-tools"+ }+ }+ }"#,+ )+ .expect("write settings");++ let outcome = service_for_paths(external_agent_home, codex_home)+ .import_plugins(/*cwd*/ None, Some(github_plugin_details()))+ .await+ .expect("import plugins");++ assert_eq!(+ outcome,PluginImportOutcome {succeeded_marketplaces: Vec::new(),succeeded_plugin_ids: Vec::new(),@@ -542,18 +1025,396 @@ async fn import_plugins_defers_marketplace_source_validation_to_add_marketplace();}+#[tokio::test]+async fn import_plugins_supports_external_agent_plugin_marketplace_layout() {+ let (_root, external_agent_home, codex_home) = fixture_paths();+ let marketplace_root = external_agent_home.join("my-marketplace");+ let plugin_root = marketplace_root.join("plugins").join("cloudflare");+ fs::create_dir_all(marketplace_root.join(".claude-plugin"))+ .expect("create marketplace manifest dir");+ fs::create_dir_all(plugin_root.join(".codex-plugin")).expect("create plugin manifest dir");+ fs::create_dir_all(&codex_home).expect("create codex home");++ fs::write(+ external_agent_home.join("settings.json"),+ serde_json::to_string_pretty(&serde_json::json!({+ "enabledPlugins": {+ "cloudflare@my-plugins": true+ },+ "extraKnownMarketplaces": {+ "my-plugins": {+ "source": "local",+ "path": marketplace_root+ }+ }+ }))+ .expect("serialize settings"),+ )+ .expect("write settings");+ fs::write(+ marketplace_root+ .join(".claude-plugin")+ .join("marketplace.json"),+ r#"{+ "name": "my-plugins",+ "plugins": [+ {+ "name": "cloudflare",+ "source": "./plugins/cloudflare"+ }+ ]+ }"#,+ )+ .expect("write marketplace manifest");+ fs::write(+ plugin_root.join(".codex-plugin").join("plugin.json"),+ r#"{"name":"cloudflare","version":"0.1.0"}"#,+ )+ .expect("write plugin manifest");++ let outcome = service_for_paths(external_agent_home, codex_home.clone())+ .import_plugins(+ /*cwd*/ None,+ Some(MigrationDetails {+ plugins: vec![PluginsMigration {+ marketplace_name: "my-plugins".to_string(),+ plugin_names: vec!["cloudflare".to_string()],+ }],+ }),+ )+ .await+ .expect("import plugins");++ assert_eq!(+ outcome,+ PluginImportOutcome {+ succeeded_marketplaces: vec!["my-plugins".to_string()],+ succeeded_plugin_ids: vec!["cloudflare@my-plugins".to_string()],+ failed_marketplaces: Vec::new(),+ failed_plugin_ids: Vec::new(),+ }+ );+ let config = fs::read_to_string(codex_home.join("config.toml")).expect("read config");+ assert!(config.contains(r#"[plugins."cloudflare@my-plugins"]"#));+ assert!(config.contains("enabled = true"));+}++#[tokio::test]+async fn detect_home_supports_relative_external_agent_plugin_marketplace_path() {+ let (_root, external_agent_home, codex_home) = fixture_paths();+ let marketplace_root = external_agent_home.join("my-marketplace");+ let plugin_root = marketplace_root.join("plugins").join("cloudflare");+ fs::create_dir_all(marketplace_root.join(".claude-plugin"))+ .expect("create marketplace manifest dir");+ fs::create_dir_all(plugin_root.join(".codex-plugin")).expect("create plugin manifest dir");+ fs::create_dir_all(&codex_home).expect("create codex home");++ fs::write(+ external_agent_home.join("settings.json"),+ r#"{+ "enabledPlugins": {+ "cloudflare@my-plugins": true+ },+ "extraKnownMarketplaces": {+ "my-plugins": {+ "source": "directory",+ "path": "./my-marketplace"+ }+ }+ }"#,+ )+ .expect("write settings");+ fs::write(+ marketplace_root+ .join(".claude-plugin")+ .join("marketplace.json"),+ r#"{+ "name": "my-plugins",+ "plugins": [+ {+ "name": "cloudflare",+ "source": "./plugins/cloudflare"+ }+ ]+ }"#,+ )+ .expect("write marketplace manifest");+ fs::write(+ plugin_root.join(".codex-plugin").join("plugin.json"),+ r#"{"name":"cloudflare","version":"0.1.0"}"#,+ )+ .expect("write plugin manifest");++ let items = service_for_paths(external_agent_home.clone(), codex_home)+ .detect(ExternalAgentConfigDetectOptions {+ include_home: true,+ cwds: None,+ })+ .await+ .expect("detect");++ assert_eq!(+ items,+ vec![ExternalAgentConfigMigrationItem {+ item_type: ExternalAgentConfigMigrationItemType::Plugins,+ description: format!(+ "Import enabled plugins from {}",+ external_agent_home.join("settings.json").display()+ ),+ cwd: None,+ details: Some(MigrationDetails {+ plugins: vec![PluginsMigration {+ marketplace_name: "my-plugins".to_string(),+ plugin_names: vec!["cloudflare".to_string()],+ }],+ }),+ }]+ );+}++#[tokio::test]+async fn import_plugins_supports_relative_external_agent_plugin_marketplace_path() {+ let (_root, external_agent_home, codex_home) = fixture_paths();+ let marketplace_root = external_agent_home.join("my-marketplace");+ let plugin_root = marketplace_root.join("plugins").join("cloudflare");+ fs::create_dir_all(marketplace_root.join(".claude-plugin"))+ .expect("create marketplace manifest dir");+ fs::create_dir_all(plugin_root.join(".codex-plugin")).expect("create plugin manifest dir");+ fs::create_dir_all(&codex_home).expect("create codex home");++ fs::write(+ external_agent_home.join("settings.json"),+ r#"{+ "enabledPlugins": {+ "cloudflare@my-plugins": true+ },+ "extraKnownMarketplaces": {+ "my-plugins": {+ "source": "directory",+ "path": "./my-marketplace"+ }+ }+ }"#,+ )+ .expect("write settings");+ fs::write(+ marketplace_root+ .join(".claude-plugin")+ .join("marketplace.json"),+ r#"{+ "name": "my-plugins",+ "plugins": [+ {+ "name": "cloudflare",+ "source": "./plugins/cloudflare"+ }+ ]+ }"#,+ )+ .expect("write marketplace manifest");+ fs::write(+ plugin_root.join(".codex-plugin").join("plugin.json"),+ r#"{"name":"cloudflare","version":"0.1.0"}"#,+ )+ .expect("write plugin manifest");++ let outcome = service_for_paths(external_agent_home, codex_home.clone())+ .import_plugins(+ /*cwd*/ None,+ Some(MigrationDetails {+ plugins: vec![PluginsMigration {+ marketplace_name: "my-plugins".to_string(),+ plugin_names: vec!["cloudflare".to_string()],+ }],+ }),+ )+ .await+ .expect("import plugins");++ assert_eq!(+ outcome,+ PluginImportOutcome {+ succeeded_marketplaces: vec!["my-plugins".to_string()],+ succeeded_plugin_ids: vec!["cloudflare@my-plugins".to_string()],+ failed_marketplaces: Vec::new(),+ failed_plugin_ids: Vec::new(),+ }+ );+ let config = fs::read_to_string(codex_home.join("config.toml")).expect("read config");+ assert!(config.contains(r#"[plugins."cloudflare@my-plugins"]"#));+ assert!(config.contains("enabled = true"));+}++#[tokio::test]+async fn detect_repo_supports_project_relative_external_agent_plugin_marketplace_path() {+ let root = TempDir::new().expect("create tempdir");+ let external_agent_home = root.path().join(".claude");+ let codex_home = root.path().join(".codex");+ let repo_root = root.path().join("repo");+ let marketplace_root = repo_root.join("my-marketplace");+ let plugin_root = marketplace_root.join("plugins").join("cloudflare");+ fs::create_dir_all(repo_root.join(".git")).expect("create git dir");+ fs::create_dir_all(repo_root.join(".claude")).expect("create repo external agent dir");+ fs::create_dir_all(marketplace_root.join(".claude-plugin"))+ .expect("create marketplace manifest dir");+ fs::create_dir_all(plugin_root.join(".codex-plugin")).expect("create plugin manifest dir");+ fs::create_dir_all(&codex_home).expect("create codex home");++ fs::write(+ repo_root.join(".claude").join("settings.json"),+ r#"{+ "enabledPlugins": {+ "cloudflare@my-plugins": true+ },+ "extraKnownMarketplaces": {+ "my-plugins": {+ "source": "directory",+ "path": "./my-marketplace"+ }+ }+ }"#,+ )+ .expect("write settings");+ fs::write(+ marketplace_root+ .join(".claude-plugin")+ .join("marketplace.json"),+ r#"{+ "name": "my-plugins",+ "plugins": [+ {+ "name": "cloudflare",+ "source": "./plugins/cloudflare"+ }+ ]+ }"#,+ )+ .expect("write marketplace manifest");+ fs::write(+ plugin_root.join(".codex-plugin").join("plugin.json"),+ r#"{"name":"cloudflare","version":"0.1.0"}"#,+ )+ .expect("write plugin manifest");++ let items = service_for_paths(external_agent_home, codex_home)+ .detect(ExternalAgentConfigDetectOptions {+ include_home: false,+ cwds: Some(vec![repo_root.clone()]),+ })+ .await+ .expect("detect");++ assert_eq!(+ items,+ vec![ExternalAgentConfigMigrationItem {+ item_type: ExternalAgentConfigMigrationItemType::Plugins,+ description: format!(+ "Import enabled plugins from {}",+ repo_root.join(".claude").join("settings.json").display()+ ),+ cwd: Some(repo_root),+ details: Some(MigrationDetails {+ plugins: vec![PluginsMigration {+ marketplace_name: "my-plugins".to_string(),+ plugin_names: vec!["cloudflare".to_string()],+ }],+ }),+ }]+ );+}++#[tokio::test]+async fn import_plugins_supports_project_relative_external_agent_plugin_marketplace_path() {+ let root = TempDir::new().expect("create tempdir");+ let external_agent_home = root.path().join(".claude");+ let codex_home = root.path().join(".codex");+ let repo_root = root.path().join("repo");+ let marketplace_root = repo_root.join("my-marketplace");+ let plugin_root = marketplace_root.join("plugins").join("cloudflare");+ fs::create_dir_all(repo_root.join(".git")).expect("create git dir");+ fs::create_dir_all(repo_root.join(".claude")).expect("create repo external agent dir");+ fs::create_dir_all(marketplace_root.join(".claude-plugin"))+ .expect("create marketplace manifest dir");+ fs::create_dir_all(plugin_root.join(".codex-plugin")).expect("create plugin manifest dir");+ fs::create_dir_all(&codex_home).expect("create codex home");++ fs::write(+ repo_root.join(".claude").join("settings.json"),+ r#"{+ "enabledPlugins": {+ "cloudflare@my-plugins": true+ },+ "extraKnownMarketplaces": {+ "my-plugins": {+ "source": "directory",+ "path": "./my-marketplace"+ }+ }+ }"#,+ )+ .expect("write settings");+ fs::write(+ marketplace_root+ .join(".claude-plugin")+ .join("marketplace.json"),+ r#"{+ "name": "my-plugins",+ "plugins": [+ {+ "name": "cloudflare",+ "source": "./plugins/cloudflare"+ }+ ]+ }"#,+ )+ .expect("write marketplace manifest");+ fs::write(+ plugin_root.join(".codex-plugin").join("plugin.json"),+ r#"{"name":"cloudflare","version":"0.1.0"}"#,+ )+ .expect("write plugin manifest");++ let outcome = service_for_paths(external_agent_home, codex_home.clone())+ .import_plugins(+ Some(repo_root.as_path()),+ Some(MigrationDetails {+ plugins: vec![PluginsMigration {+ marketplace_name: "my-plugins".to_string(),+ plugin_names: vec!["cloudflare".to_string()],+ }],+ }),+ )+ .await+ .expect("import plugins");++ assert_eq!(+ outcome,+ PluginImportOutcome {+ succeeded_marketplaces: vec!["my-plugins".to_string()],+ succeeded_plugin_ids: vec!["cloudflare@my-plugins".to_string()],+ failed_marketplaces: Vec::new(),+ failed_plugin_ids: Vec::new(),+ }+ );+ let config = fs::read_to_string(codex_home.join("config.toml")).expect("read config");+ assert!(config.contains(r#"[plugins."cloudflare@my-plugins"]"#));+ assert!(config.contains("enabled = true"));+}+#[test]fn import_skills_returns_only_new_skill_directory_count() {- let (_root, claude_home, codex_home) = fixture_paths();+ let (_root, external_agent_home, codex_home) = fixture_paths();let agents_skills = codex_home.parent().map(|parent| parent.join(".agents").join("skills")).unwrap_or_else(|| PathBuf::from(".agents").join("skills"));- fs::create_dir_all(claude_home.join("skills").join("skill-a")).expect("create source a");- fs::create_dir_all(claude_home.join("skills").join("skill-b")).expect("create source b");+ fs::create_dir_all(external_agent_home.join("skills").join("skill-a"))+ .expect("create source a");+ fs::create_dir_all(external_agent_home.join("skills").join("skill-b"))+ .expect("create source b");fs::create_dir_all(agents_skills.join("skill-a")).expect("create existing target");- let copied_count = service_for_paths(claude_home, codex_home)+ let copied_count = service_for_paths(external_agent_home, codex_home).import_skills(/*cwd*/ None).expect("import skills");diff --git a/codex-rs/core/src/plugins/manager.rs b/codex-rs/core/src/plugins/manager.rsindex 50c62d5823..3449ecffdf 100644--- a/codex-rs/core/src/plugins/manager.rs+++ b/codex-rs/core/src/plugins/manager.rs@@ -1346,7 +1346,7 @@ impl PluginUninstallError {}}-fn configured_plugins_from_stack(+pub(crate) fn configured_plugins_from_stack(config_layer_stack: &ConfigLayerStack,) -> HashMap<String, PluginConfig> {// Plugin entries remain persisted user config only.diff --git a/codex-rs/core/src/plugins/marketplace_add.rs b/codex-rs/core/src/plugins/marketplace_add.rsindex b8d1b34d41..38fc04c199 100644--- a/codex-rs/core/src/plugins/marketplace_add.rs+++ b/codex-rs/core/src/plugins/marketplace_add.rs@@ -20,7 +20,7 @@ use metadata::find_marketplace_root_by_name;use metadata::installed_marketplace_root_for_source;use metadata::record_added_marketplace_entry;use source::MarketplaceSource;-use source::parse_marketplace_source;+pub(crate) use source::parse_marketplace_source;use source::stage_marketplace_source;use source::validate_marketplace_source_root;diff --git a/codex-rs/core/src/plugins/marketplace_add/source.rs b/codex-rs/core/src/plugins/marketplace_add/source.rsindex 9a0b666c60..98bdc2b8bb 100644--- a/codex-rs/core/src/plugins/marketplace_add/source.rs+++ b/codex-rs/core/src/plugins/marketplace_add/source.rs@@ -5,7 +5,7 @@ use std::path::Path;use std::path::PathBuf;#[derive(Debug, Clone, PartialEq, Eq)]-pub(super) enum MarketplaceSource {+pub(crate) enum MarketplaceSource {Git {url: String,ref_name: Option<String>,@@ -15,7 +15,7 @@ pub(super) enum MarketplaceSource {},}-pub(super) fn parse_marketplace_source(+pub(crate) fn parse_marketplace_source(source: &str,explicit_ref: Option<String>,) -> Result<MarketplaceSource, MarketplaceAddError> {diff --git a/codex-rs/core/src/plugins/mod.rs b/codex-rs/core/src/plugins/mod.rsindex 57997eb134..2e86643f34 100644--- a/codex-rs/core/src/plugins/mod.rs+++ b/codex-rs/core/src/plugins/mod.rs@@ -22,6 +22,7 @@ pub use codex_plugin::validate_plugin_segment;pub type LoadedPlugin = codex_plugin::LoadedPlugin<McpServerConfig>;pub type PluginLoadOutcome = codex_plugin::PluginLoadOutcome<McpServerConfig>;+pub(crate) use codex_core_plugins::marketplace::find_marketplace_manifest_path;pub(crate) use discoverable::list_tool_suggest_discoverable_plugins;pub(crate) use injection::build_plugin_injections;pub use installed_marketplaces::INSTALLED_MARKETPLACES_DIR;@@ -40,10 +41,12 @@ pub use manager::PluginRemoteSyncError;pub use manager::PluginUninstallError;pub use manager::PluginsManager;pub use manager::RemotePluginSyncResult;+pub(crate) use manager::configured_plugins_from_stack;pub use marketplace_add::MarketplaceAddError;pub use marketplace_add::MarketplaceAddOutcome;pub use marketplace_add::MarketplaceAddRequest;pub use marketplace_add::add_marketplace;+pub(crate) use marketplace_add::parse_marketplace_source;pub(crate) use render::render_explicit_plugin_instructions;pub(crate) use render::render_plugins_section;pub(crate) use startup_sync::curated_plugins_repo_path;