Skip to content

Commit df60640

Browse files
mpc-oaicopyberry
authored andcommitted
Load managed cloud config for plugin add and list (#62837)
## Why `codex plugin add` and `codex plugin list` loaded configuration without the managed cloud configuration layer, so plugin discovery and installation could miss settings supplied by that layer. ## What changed Use the shared cloud-aware configuration builder for add and list, passing through CLI overrides. Keep `codex plugin remove` on the local configuration loader and use the loaded configuration's Codex home for all three commands. GitOrigin-RevId: 5ebe94de30e553c57ae6296a2ddb91792260a61f
1 parent 1c0c806 commit df60640

2 files changed

Lines changed: 33 additions & 29 deletions

File tree

‎codex-rs/cli/src/main.rs‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,26 +1274,17 @@ async fn dispatch_cli(
12741274
prepend_config_flags(&mut config_overrides, root_config_overrides.clone());
12751275
match subcommand {
12761276
PluginSubcommand::Add(args) => {
1277-
let overrides = config_overrides
1278-
.parse_overrides()
1279-
.map_err(anyhow::Error::msg)?;
1280-
plugin_cmd::run_plugin_add(overrides, args).await?;
1277+
plugin_cmd::run_plugin_add(&config_overrides, args).await?;
12811278
}
12821279
PluginSubcommand::List(args) => {
1283-
let overrides = config_overrides
1284-
.parse_overrides()
1285-
.map_err(anyhow::Error::msg)?;
1286-
plugin_cmd::run_plugin_list(overrides, args).await?;
1280+
plugin_cmd::run_plugin_list(&config_overrides, args).await?;
12871281
}
12881282
PluginSubcommand::Marketplace(mut marketplace_cli) => {
12891283
prepend_config_flags(&mut marketplace_cli.config_overrides, config_overrides);
12901284
marketplace_cli.run().await?;
12911285
}
12921286
PluginSubcommand::Remove(args) => {
1293-
let overrides = config_overrides
1294-
.parse_overrides()
1295-
.map_err(anyhow::Error::msg)?;
1296-
plugin_cmd::run_plugin_remove(overrides, args).await?;
1287+
plugin_cmd::run_plugin_remove(&config_overrides, args).await?;
12971288
}
12981289
}
12991290
}

‎codex-rs/cli/src/plugin_cmd.rs‎

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use clap::Parser;
66
use codex_app_server_protocol::PluginAuthPolicy;
77
use codex_app_server_protocol::PluginInstallPolicy;
88
use codex_core::config::Config;
9-
use codex_core::config::find_codex_home;
9+
use codex_core::config::ConfigOverrides;
10+
use codex_core::config::LoaderOverrides;
1011
use codex_core::plugins_manager_for_config;
1112
use codex_core::plugins_manager_for_config_with_runtime;
1213
use codex_core_plugins::ConfiguredMarketplace;
@@ -44,6 +45,7 @@ use std::path::Path;
4445
use std::path::PathBuf;
4546
use std::sync::Arc;
4647

48+
use crate::cloud_config;
4749
use crate::marketplace_cmd::MarketplaceCli;
4850

4951
const OPENAI_BUNDLED_ALPHA_MARKETPLACE_NAME: &str = "openai-bundled-alpha";
@@ -137,10 +139,7 @@ pub struct RemovePluginArgs {
137139
json: bool,
138140
}
139141

140-
pub async fn run_plugin_add(
141-
overrides: Vec<(String, toml::Value)>,
142-
args: AddPluginArgs,
143-
) -> Result<()> {
142+
pub async fn run_plugin_add(overrides: &CliConfigOverrides, args: AddPluginArgs) -> Result<()> {
144143
let AddPluginArgs {
145144
plugin,
146145
marketplace_name,
@@ -244,10 +243,7 @@ impl JsonPluginAddOutput {
244243
}
245244
}
246245

247-
pub async fn run_plugin_list(
248-
overrides: Vec<(String, toml::Value)>,
249-
args: ListPluginsArgs,
250-
) -> Result<()> {
246+
pub async fn run_plugin_list(overrides: &CliConfigOverrides, args: ListPluginsArgs) -> Result<()> {
251247
let context = load_plugin_command_context(overrides, args.marketplace_name.as_deref()).await?;
252248
let remote_listing = fetch_remote_marketplaces(
253249
&context,
@@ -680,7 +676,7 @@ fn auth_policy_label(policy: MarketplacePluginAuthPolicy) -> &'static str {
680676
}
681677

682678
pub async fn run_plugin_remove(
683-
overrides: Vec<(String, toml::Value)>,
679+
overrides: &CliConfigOverrides,
684680
args: RemovePluginArgs,
685681
) -> Result<()> {
686682
let RemovePluginArgs {
@@ -689,7 +685,12 @@ pub async fn run_plugin_remove(
689685
json,
690686
} = args;
691687
let selection = parse_plugin_selection(plugin, marketplace_name)?;
692-
let context = load_plugin_command_context(overrides, Some(&selection.marketplace_name)).await?;
688+
let overrides = overrides.parse_overrides().map_err(anyhow::Error::msg)?;
689+
let config = Config::load_with_cli_overrides(overrides)
690+
.await
691+
.context("failed to load configuration")?;
692+
let context =
693+
plugin_command_context_from_config(config, Some(&selection.marketplace_name)).await?;
693694

694695
if selection.marketplace_name == REMOTE_GLOBAL_MARKETPLACE_NAME {
695696
ensure!(
@@ -766,13 +767,25 @@ struct PluginCommandContext {
766767
}
767768

768769
async fn load_plugin_command_context(
769-
overrides: Vec<(String, toml::Value)>,
770+
overrides: &CliConfigOverrides,
771+
marketplace_name: Option<&str>,
772+
) -> Result<PluginCommandContext> {
773+
let config = cloud_config::config_builder(
774+
overrides,
775+
LoaderOverrides::default(),
776+
ConfigOverrides::default(),
777+
)
778+
.await?
779+
.build()
780+
.await
781+
.context("failed to load configuration")?;
782+
plugin_command_context_from_config(config, marketplace_name).await
783+
}
784+
785+
async fn plugin_command_context_from_config(
786+
config: Config,
770787
marketplace_name: Option<&str>,
771788
) -> Result<PluginCommandContext> {
772-
let codex_home = find_codex_home().context("failed to resolve CODEX_HOME")?;
773-
let config = Config::load_with_cli_overrides(overrides)
774-
.await
775-
.context("failed to load configuration")?;
776789
let plugins_input = config.plugins_config_input();
777790
let auth_manager = load_cli_auth_manager(&config).await?;
778791
let auth = auth_manager.auth().await;
@@ -785,7 +798,7 @@ async fn load_plugin_command_context(
785798
plugins_manager_for_config(&config, Arc::clone(&auth_manager))
786799
});
787800
Ok(PluginCommandContext {
788-
codex_home: codex_home.to_path_buf(),
801+
codex_home: config.codex_home.to_path_buf(),
789802
plugins_input,
790803
manager,
791804
auth,

0 commit comments

Comments
 (0)