Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 70 additions & 4 deletions mesh/crates/mesh-llm-commands/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use mesh_llm_plugin_manager::defaults::{
DEFAULT_PLUGINS, DefaultPluginOutcome, NO_DEFAULT_PLUGINS_ENV, default_plugin,
default_plugins_opted_out, provision_bundled_defaults, turn_off_defaults,
};
use mesh_llm_plugin_manager::install::install_plugin_archive;
use mesh_llm_plugin_manager::install::{install_plugin_archive, install_plugin_requirements};
use mesh_llm_plugin_manager::requirements::{ensure_not_required, missing_requirements};
use mesh_llm_plugin_manager::{
PluginCatalog, PluginInstallOptions, PluginProgressEvent, PluginProgressReporter, PluginStore,
PluginTarget, default_store_root, install_plugin, update_plugin,
Expand Down Expand Up @@ -179,7 +180,9 @@ async fn install(
let outcome = match (reference, archive, name) {
(Some(reference), None, None) => install_plugin(reference, &options, &mut progress).await?,
(None, Some(archive), Some(name)) => {
install_plugin_archive(name, version, archive, &options, &mut progress)?
let outcome = install_plugin_archive(name, version, archive, &options, &mut progress)?;
install_plugin_requirements(&outcome.metadata, &options, &mut progress).await?;
outcome
}
_ => bail!("provide either a plugin reference or --archive with --name"),
};
Expand Down Expand Up @@ -298,6 +301,7 @@ fn delete(name: &str) -> Result<()> {
}

fn delete_in(store: &PluginStore, name: &str, err: &mut impl Write) -> Result<()> {
ensure_not_required(store, name, "delete")?;
store.delete(name)?;
writeln!(err, "🗑️ Deleted {name}")?;
// A deleted default stays removed: delete leaves the record that `plugins
Expand Down Expand Up @@ -432,18 +436,28 @@ async fn search(query: Option<&str>) -> Result<()> {
fn list(runtime_rows: &PluginListRows) -> Result<()> {
let store = PluginStore::new(default_store_root()?);
let mut out = mesh_llm_events::console_out();
for metadata in store.list()? {
let installed = store.list()?;
for metadata in &installed {
let state = if metadata.enabled {
"enabled"
} else {
"disabled"
};
let requires = if metadata.requires.is_empty() {
String::new()
} else {
format!("\trequires={}", metadata.requires.join(","))
};
writeln!(
out,
"{}\tversion={}\tstate={}\tsource={}",
"{}\tversion={}\tstate={}\tsource={}{requires}",
metadata.name, metadata.installed_version, state, metadata.source_repository
)?;
}
let mut err = mesh_llm_events::console_err();
for missing in missing_requirements(&installed) {
writeln!(err, "⚠️ {}", missing.describe())?;
}

for spec in &runtime_rows.externals {
writeln!(
Expand Down Expand Up @@ -569,6 +583,11 @@ impl PluginProgressReporter for CliPluginProgress {
let mut err = mesh_llm_events::console_err();
let _ = writeln!(err, "✅ {name} is up to date ({version})");
}
PluginProgressEvent::InstallingRequirement { plugin, required } => {
self.finish();
let mut err = mesh_llm_events::console_err();
let _ = writeln!(err, "🔗 {plugin} requires {required}; installing it");
}
}
}
}
Expand Down Expand Up @@ -695,6 +714,7 @@ url = "unix:///run/remote.sock"
install_path: store.root().join("installed").join("capsules"),
enabled,
default_managed: false,
requires: Vec::new(),
manifest: None,
last_protocol_version: None,
last_status: None,
Expand Down Expand Up @@ -820,6 +840,52 @@ url = "unix:///run/remote.sock"
assert!(!String::from_utf8(err).unwrap().contains("default plugin"));
}

fn installed_plugin(
store: &PluginStore,
name: &str,
requires: &[&str],
) -> mesh_llm_plugin_manager::InstalledPluginMetadata {
let metadata = mesh_llm_plugin_manager::InstalledPluginMetadata {
name: name.into(),
source_repository: format!("https://github.com/Mesh-LLM/{name}"),
installed_version: "v0.1.0".into(),
target_triple: "x86_64-unknown-linux-gnu".into(),
downloaded_asset_name: format!("{name}-0.1.0-x86_64-unknown-linux-gnu.tar.gz"),
install_path: store.root().join("installed").join(name),
enabled: true,
default_managed: false,
requires: requires.iter().map(|value| value.to_string()).collect(),
manifest: None,
last_protocol_version: None,
last_status: None,
last_error: None,
};
store.save(&metadata).unwrap();
metadata
}

#[test]
fn deleting_a_plugin_another_one_requires_is_refused_and_keeps_it_installed() {
let temp = tempfile::tempdir().unwrap();
let store = PluginStore::new(temp.path());
installed_plugin(&store, "lexe-wallet", &["pay-lightning"]);
installed_plugin(&store, "pay-lightning", &[]);
let mut err = Vec::new();

let error = delete_in(&store, "pay-lightning", &mut err).unwrap_err();

assert_eq!(
error.to_string(),
"cannot delete pay-lightning: required by lexe-wallet; delete it first"
);
assert!(store.load_optional("pay-lightning").unwrap().is_some());
assert!(err.is_empty());

delete_in(&store, "lexe-wallet", &mut err).unwrap();
delete_in(&store, "pay-lightning", &mut err).unwrap();
assert!(store.list().unwrap().is_empty());
}

#[test]
fn install_defaults_turned_off_by_the_environment_says_so() {
let line = turned_off_by_environment_line();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ mod tests {
install_path,
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: Some(InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: Some(InstalledPluginConfigSchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ fn install_blackboard_schema(plugin_dir: &std::path::Path) {
install_path: std::env::temp_dir().join("mesh-llm-plugin-blackboard-api-tests"),
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: Some(InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: Some(blackboard_schema()),
Expand Down
3 changes: 3 additions & 0 deletions mesh/crates/mesh-llm-host-runtime/src/config_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ mod tests {
install_path: PathBuf::from("/tmp/blackboard"),
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: Some(InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: None,
Expand Down Expand Up @@ -1265,6 +1266,7 @@ mod tests {
install_path: PathBuf::from("/tmp/blackboard"),
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: Some(InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: Some(InstalledPluginConfigSchema {
Expand Down Expand Up @@ -1340,6 +1342,7 @@ mod tests {
install_path: PathBuf::from(format!("/tmp/{plugin_name}")),
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: Some(InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: Some(InstalledPluginConfigSchema {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ fn installed_plugin_metadata(
install_path: std::env::temp_dir().join(format!("mesh-llm-plugin-{name}")),
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: Some(InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: schema,
Expand Down
27 changes: 26 additions & 1 deletion mesh/crates/mesh-llm-host-runtime/src/plugin/installed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use super::config::{ExternalPluginSpec, PluginConfigEntry};
use super::startup::PluginStartupOptions;
use super::{PluginSummary, PluginWebUiState, derive_plugin_web_ui_state};
use anyhow::{Context, Result, bail};
use mesh_llm_plugin_manager::{InstalledPluginMetadata, PluginStore, default_store_root};
use mesh_llm_plugin_manager::{
InstalledPluginMetadata, PluginStore, default_store_root, missing_requirements,
};
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -151,6 +153,7 @@ pub(crate) fn append_installed_plugins(
return;
}
};
warn_once_about_missing_requirements(&installed);

for metadata in installed {
if names.contains_key(&metadata.name) {
Expand All @@ -170,6 +173,28 @@ pub(crate) fn append_installed_plugins(
}
}

/// A plugin whose `plugin.toml` requirement is not installed, or is disabled,
/// still starts: how it reaches the other plugin is an operator-authorized
/// binding, not something the host wires. Say so at start rather than
/// leaving it to be discovered at the first call. An output event, not
/// `tracing::warn!`: the runtime's default log filter drops host-runtime
/// warnings. Plugins are resolved more than once at startup; warn once.
fn warn_once_about_missing_requirements(installed: &[InstalledPluginMetadata]) {
static WARNED: std::sync::Once = std::sync::Once::new();
let missing = missing_requirements(installed);
if missing.is_empty() {
return;
}
WARNED.call_once(|| {
for requirement in missing {
let _ = mesh_llm_events::emit_event(mesh_llm_events::OutputEvent::Warning {
message: format!("Plugin {}", requirement.describe()),
context: None,
});
}
});
}

fn installed_plugin_command_for_name(name: &str) -> Result<String> {
let root = default_store_root().context("Cannot determine plugin install root")?;
let store = PluginStore::new(root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn installed_capsules(store_root: &Path, enabled: bool) -> InstalledPluginMetada
install_path: store_root.join("installs").join("capsules"),
enabled,
default_managed: true,
requires: Vec::new(),
manifest: Some(InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: None,
Expand Down
1 change: 1 addition & 0 deletions mesh/crates/mesh-llm-host-runtime/src/plugin/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ pub(crate) mod tests {
install_path,
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: Some(InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ mod tests {
install_path: root.into(),
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: None,
last_protocol_version: None,
last_status: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ mod tests {
install_path: PathBuf::from("/tmp/blackboard"),
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: Some(InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: Some(InstalledPluginConfigSchema {
Expand Down
1 change: 1 addition & 0 deletions mesh/crates/mesh-llm-host-runtime/src/plugin/web_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ pub(super) fn installed_metadata_with_web_ui(
install_path,
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: Some(mesh_llm_plugin_manager::InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ pub(super) fn installed_plugin_metadata(
install_path: std::env::temp_dir().join(format!("mesh-llm-plugin-{name}")),
enabled: true,
default_managed: false,
requires: Vec::new(),
manifest: Some(InstalledPluginManifestMetadata {
openai_exchange_hook: None,
config_schema: schema,
Expand Down
1 change: 1 addition & 0 deletions mesh/crates/mesh-llm-plugin-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ serde_json.workspace = true
sha2.workspace = true
tar = "0.4"
tempfile = "3"
toml = "1.1"
zip = { version = "9", default-features = false, features = ["deflate"] }
9 changes: 9 additions & 0 deletions mesh/crates/mesh-llm-plugin-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ authoring and release validation can pass a `.tar.gz` or `.zip` directly to
boundary. It deliberately
does not render CLI output; callers should render progress and status events in
the host application.

## Plugin requirements

`plugin.toml` may list `requires = ["<catalog-name>", ...]`. `plugin_toml`
parses it at install, the install metadata records it, and `requirements`
answers what an install must fetch (`install_plugin` does so from the catalog,
recursively), what a delete must refuse, and what a node start or
`plugins list` should report as missing or disabled. The host never starts,
orders, or connects plugins for each other on the strength of a requirement.
5 changes: 5 additions & 0 deletions mesh/crates/mesh-llm-plugin-manager/src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anyhow::{Context, Result, bail};
use flate2::read::GzDecoder;

use crate::{
plugin_toml::read_plugin_toml,
store::{
InstalledPluginManifestMetadata, InstalledPluginWebUiMetadata,
InstalledPluginWebUiValidation, InstalledPluginWebUiValidationStatus,
Expand All @@ -23,6 +24,8 @@ const WEB_UI_CONTRIBUTION_SLOTS: [&str; 2] = ["chat_message", "logs_request"];
pub struct ExtractedPluginArchive {
pub install_path: PathBuf,
pub manifest: Option<InstalledPluginManifestMetadata>,
/// Installed plugins this one requires, from its `plugin.toml`.
pub requires: Vec<String>,
}

pub fn extract_plugin_archive(
Expand All @@ -45,13 +48,15 @@ pub fn extract_plugin_archive(
let extracted_root = find_plugin_root(staging.path(), plugin_name)?;
validate_plugin_root(&extracted_root, plugin_name, executable_suffix)?;
let manifest = load_packaged_manifest(&extracted_root, plugin_name)?;
let requires = read_plugin_toml(&extracted_root, plugin_name)?.requires;
let final_dir = install_dir.join(plugin_name);
fs::create_dir_all(install_dir)
.with_context(|| format!("create plugin install dir {}", install_dir.display()))?;
replace_plugin_dir(&extracted_root, &final_dir, plugin_name)?;
Ok(ExtractedPluginArchive {
install_path: final_dir,
manifest,
requires,
})
}

Expand Down
1 change: 1 addition & 0 deletions mesh/crates/mesh-llm-plugin-manager/src/bundled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub fn install_bundled_default(
install_path: extracted.install_path,
enabled: current.as_ref().map(|item| item.enabled).unwrap_or(true),
default_managed: true,
requires: extracted.requires,
manifest: extracted.manifest,
last_protocol_version: current.as_ref().and_then(|item| item.last_protocol_version),
last_status: current.as_ref().and_then(|item| item.last_status.clone()),
Expand Down
1 change: 1 addition & 0 deletions mesh/crates/mesh-llm-plugin-manager/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ mod tests {
install_path: "/tmp/notes".into(),
enabled,
default_managed: managed,
requires: Vec::new(),
manifest: None,
last_protocol_version: None,
last_status: None,
Expand Down
Loading
Loading