mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Add marketplace update check RPC
This commit is contained in:
@@ -51,6 +51,9 @@ pub use manager::PluginUninstallError;
|
||||
pub use manager::PluginsConfigInput;
|
||||
pub use manager::PluginsManager;
|
||||
pub use manager::RecommendedPluginCandidatesInput;
|
||||
pub use marketplace_upgrade::ConfiguredMarketplaceUpdateCheck as PluginMarketplaceUpdateCheck;
|
||||
pub use marketplace_upgrade::ConfiguredMarketplaceUpdateCheckOutcome as PluginMarketplaceUpdateCheckOutcome;
|
||||
pub use marketplace_upgrade::ConfiguredMarketplaceUpdateStatus as PluginMarketplaceUpdateStatus;
|
||||
pub use marketplace_upgrade::ConfiguredMarketplaceUpgradeError as PluginMarketplaceUpgradeError;
|
||||
pub use marketplace_upgrade::ConfiguredMarketplaceUpgradeOutcome as PluginMarketplaceUpgradeOutcome;
|
||||
pub use provider::ExecutorPluginProvider;
|
||||
|
||||
@@ -34,8 +34,10 @@ use crate::marketplace::find_installable_marketplace_plugin;
|
||||
use crate::marketplace::find_marketplace_plugin;
|
||||
use crate::marketplace::list_marketplaces;
|
||||
use crate::marketplace::plugin_interface_with_marketplace_category;
|
||||
use crate::marketplace_upgrade::ConfiguredMarketplaceUpdateCheckOutcome;
|
||||
use crate::marketplace_upgrade::ConfiguredMarketplaceUpgradeError;
|
||||
use crate::marketplace_upgrade::ConfiguredMarketplaceUpgradeOutcome;
|
||||
use crate::marketplace_upgrade::check_configured_git_marketplace_updates;
|
||||
use crate::marketplace_upgrade::configured_git_marketplace_names;
|
||||
use crate::marketplace_upgrade::upgrade_configured_git_marketplaces;
|
||||
use crate::remote::REMOTE_GLOBAL_MARKETPLACE_NAME;
|
||||
@@ -1958,15 +1960,7 @@ impl PluginsManager {
|
||||
config: &PluginsConfigInput,
|
||||
marketplace_name: Option<&str>,
|
||||
) -> Result<ConfiguredMarketplaceUpgradeOutcome, String> {
|
||||
if let Some(marketplace_name) = marketplace_name
|
||||
&& !configured_git_marketplace_names(&config.config_layer_stack)
|
||||
.iter()
|
||||
.any(|name| name == marketplace_name)
|
||||
{
|
||||
return Err(format!(
|
||||
"marketplace `{marketplace_name}` is not configured as a Git marketplace"
|
||||
));
|
||||
}
|
||||
validate_configured_git_marketplace_selection(config, marketplace_name)?;
|
||||
|
||||
let mut outcome = upgrade_configured_git_marketplaces(
|
||||
self.codex_home.as_path(),
|
||||
@@ -1997,6 +1991,19 @@ impl PluginsManager {
|
||||
Ok(outcome)
|
||||
}
|
||||
|
||||
pub fn check_configured_marketplace_updates_for_config(
|
||||
&self,
|
||||
config: &PluginsConfigInput,
|
||||
marketplace_name: Option<&str>,
|
||||
) -> Result<ConfiguredMarketplaceUpdateCheckOutcome, String> {
|
||||
validate_configured_git_marketplace_selection(config, marketplace_name)?;
|
||||
Ok(check_configured_git_marketplace_updates(
|
||||
self.codex_home.as_path(),
|
||||
&config.config_layer_stack,
|
||||
marketplace_name,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn maybe_start_non_curated_plugin_cache_refresh(
|
||||
self: &Arc<Self>,
|
||||
roots: &[AbsolutePathBuf],
|
||||
@@ -2401,6 +2408,22 @@ impl PluginsManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_configured_git_marketplace_selection(
|
||||
config: &PluginsConfigInput,
|
||||
marketplace_name: Option<&str>,
|
||||
) -> Result<(), String> {
|
||||
if let Some(marketplace_name) = marketplace_name
|
||||
&& !configured_git_marketplace_names(&config.config_layer_stack)
|
||||
.iter()
|
||||
.any(|name| name == marketplace_name)
|
||||
{
|
||||
return Err(format!(
|
||||
"marketplace `{marketplace_name}` is not configured as a Git marketplace"
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn remote_plugin_install_required_description(
|
||||
source: &MarketplacePluginSource,
|
||||
) -> String {
|
||||
|
||||
@@ -38,6 +38,24 @@ pub struct ConfiguredMarketplaceUpgradeOutcome {
|
||||
pub errors: Vec<ConfiguredMarketplaceUpgradeError>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
pub struct ConfiguredMarketplaceUpdateCheckOutcome {
|
||||
pub results: Vec<ConfiguredMarketplaceUpdateCheck>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ConfiguredMarketplaceUpdateCheck {
|
||||
pub marketplace_name: String,
|
||||
pub status: ConfiguredMarketplaceUpdateStatus,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ConfiguredMarketplaceUpdateStatus {
|
||||
UpToDate,
|
||||
UpdateAvailable,
|
||||
Error { message: String },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
struct ConfiguredGitMarketplace {
|
||||
name: String,
|
||||
@@ -62,6 +80,39 @@ pub fn configured_git_marketplace_names(config_layer_stack: &ConfigLayerStack) -
|
||||
names
|
||||
}
|
||||
|
||||
pub fn check_configured_git_marketplace_updates(
|
||||
codex_home: &Path,
|
||||
config_layer_stack: &ConfigLayerStack,
|
||||
marketplace_name: Option<&str>,
|
||||
) -> ConfiguredMarketplaceUpdateCheckOutcome {
|
||||
let install_root = marketplace_install_root(codex_home);
|
||||
let results = configured_git_marketplaces(config_layer_stack)
|
||||
.into_iter()
|
||||
.filter(|marketplace| marketplace_name.is_none_or(|name| marketplace.name == name))
|
||||
.map(|marketplace| {
|
||||
let status = match configured_git_marketplace_remote_revision(&marketplace) {
|
||||
Ok(remote_revision)
|
||||
if configured_git_marketplace_is_up_to_date(
|
||||
&install_root,
|
||||
&marketplace,
|
||||
&remote_revision,
|
||||
) =>
|
||||
{
|
||||
ConfiguredMarketplaceUpdateStatus::UpToDate
|
||||
}
|
||||
Ok(_) => ConfiguredMarketplaceUpdateStatus::UpdateAvailable,
|
||||
Err(message) => ConfiguredMarketplaceUpdateStatus::Error { message },
|
||||
};
|
||||
ConfiguredMarketplaceUpdateCheck {
|
||||
marketplace_name: marketplace.name,
|
||||
status,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
ConfiguredMarketplaceUpdateCheckOutcome { results }
|
||||
}
|
||||
|
||||
pub fn upgrade_configured_git_marketplaces(
|
||||
codex_home: &Path,
|
||||
config_layer_stack: &ConfigLayerStack,
|
||||
@@ -170,20 +221,13 @@ fn upgrade_configured_git_marketplace(
|
||||
install_root: &Path,
|
||||
marketplace: &ConfiguredGitMarketplace,
|
||||
) -> Result<Option<AbsolutePathBuf>, String> {
|
||||
validate_plugin_segment(&marketplace.name, "marketplace name")?;
|
||||
let remote_revision = git_remote_revision(
|
||||
&marketplace.source,
|
||||
marketplace.ref_name.as_deref(),
|
||||
MARKETPLACE_UPGRADE_GIT_TIMEOUT,
|
||||
)?;
|
||||
let destination = install_root.join(&marketplace.name);
|
||||
if find_marketplace_manifest_path(&destination).is_some()
|
||||
&& marketplace.last_revision.as_deref() == Some(remote_revision.as_str())
|
||||
&& installed_marketplace_metadata_matches(&destination, marketplace, &remote_revision)
|
||||
{
|
||||
let remote_revision = configured_git_marketplace_remote_revision(marketplace)?;
|
||||
if configured_git_marketplace_is_up_to_date(install_root, marketplace, &remote_revision) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let destination = install_root.join(&marketplace.name);
|
||||
|
||||
let staging_parent = install_root.join(".staging");
|
||||
std::fs::create_dir_all(&staging_parent).map_err(|err| {
|
||||
format!(
|
||||
@@ -241,6 +285,28 @@ fn upgrade_configured_git_marketplace(
|
||||
.map(Some)
|
||||
.map_err(|err| format!("upgraded marketplace path is not absolute: {err}"))
|
||||
}
|
||||
|
||||
fn configured_git_marketplace_remote_revision(
|
||||
marketplace: &ConfiguredGitMarketplace,
|
||||
) -> Result<String, String> {
|
||||
validate_plugin_segment(&marketplace.name, "marketplace name")?;
|
||||
git_remote_revision(
|
||||
&marketplace.source,
|
||||
marketplace.ref_name.as_deref(),
|
||||
MARKETPLACE_UPGRADE_GIT_TIMEOUT,
|
||||
)
|
||||
}
|
||||
|
||||
fn configured_git_marketplace_is_up_to_date(
|
||||
install_root: &Path,
|
||||
marketplace: &ConfiguredGitMarketplace,
|
||||
remote_revision: &str,
|
||||
) -> bool {
|
||||
let destination = install_root.join(&marketplace.name);
|
||||
find_marketplace_manifest_path(&destination).is_some()
|
||||
&& marketplace.last_revision.as_deref() == Some(remote_revision)
|
||||
&& installed_marketplace_metadata_matches(&destination, marketplace, remote_revision)
|
||||
}
|
||||
fn ensure_configured_git_marketplace_unchanged(
|
||||
codex_home: &Path,
|
||||
expected: &ConfiguredGitMarketplace,
|
||||
|
||||
Reference in New Issue
Block a user