sparrow/cmd_handlers/
handle_plugins_cmd.rs1pub fn handle_plugins(
3 action: sparrow::cli::PluginsAction,
4 config_dir: &std::path::Path,
5) -> anyhow::Result<()> {
6 let plugins_dir = config_dir.join("plugins");
7 match action {
8 sparrow::cli::PluginsAction::List => {
9 let registry = sparrow::capabilities::plugin::PluginRegistry::new(plugins_dir);
10 let plugins = registry.scan();
11 if plugins.is_empty() {
12 println!("No plugins installed.");
13 } else {
14 println!("Plugins ({}):", plugins.len());
15 for plugin in plugins {
16 let audit = registry.audit(&plugin);
17 println!(
18 " {} {} | commands:{} skills:{} hooks:{} | {}",
19 plugin.manifest.name,
20 plugin.manifest.version,
21 plugin.manifest.commands.len(),
22 plugin.manifest.skills.len(),
23 plugin.manifest.hooks.len(),
24 if audit.allowed { "allowed" } else { "blocked" }
25 );
26 for warning in audit.warnings {
27 println!(" - {}", warning);
28 }
29 }
30 }
31 }
32 sparrow::cli::PluginsAction::Install { source, allow } => {
33 let source_path = std::path::PathBuf::from(&source);
34 let mut allowlist = Vec::new();
35 if allow {
36 if let Ok(plugin) = sparrow::capabilities::plugin::load_plugin(&source_path) {
37 allowlist.push(plugin.manifest.name);
38 }
39 }
40 let registry = sparrow::capabilities::plugin::PluginRegistry::new(plugins_dir)
41 .with_allowlist(allowlist);
42 let plugin = if source.starts_with("http://")
43 || source.starts_with("https://")
44 || source.ends_with(".git")
45 || source.contains("github.com")
46 {
47 registry.install_github(&source)?
48 } else {
49 registry.install_local(&source_path)?
50 };
51 println!("Installed plugin '{}'.", plugin.manifest.name);
52 }
53 sparrow::cli::PluginsAction::Rm { name } => {
54 let path = plugins_dir.join(&name);
55 if path.exists() {
56 std::fs::remove_dir_all(path)?;
57 println!("Removed plugin '{}'.", name);
58 } else {
59 println!("No plugin named '{}'.", name);
60 }
61 }
62 }
63 Ok(())
64}