systemprompt_cli/commands/core/plugins/
show.rs1use anyhow::{Context, Result, anyhow};
7use clap::Args;
8use std::path::Path;
9
10use crate::CliConfig;
11use crate::shared::CommandOutput;
12
13use super::types::{PluginComponentRef, PluginDetailOutput};
14
15#[derive(Debug, Clone, Args)]
16pub struct ShowArgs {
17 #[arg(help = "Plugin ID (directory name)")]
18 pub id: String,
19}
20
21pub(super) fn execute(args: &ShowArgs, _config: &CliConfig) -> Result<CommandOutput> {
22 let plugins_path = get_plugins_path()?;
23 let plugin_dir = plugins_path.join(&args.id);
24
25 if !plugin_dir.exists() {
26 return Err(anyhow!("Plugin '{}' not found", args.id));
27 }
28
29 let config_path = plugin_dir.join("config.yaml");
30 if !config_path.exists() {
31 return Err(anyhow!("Plugin '{}' has no config.yaml file", args.id));
32 }
33
34 let plugin_file = parse_plugin_config(&config_path)?;
35 let plugin = &plugin_file.plugin;
36
37 let output = PluginDetailOutput {
38 id: systemprompt_identifiers::PluginId::new(plugin.id.clone()),
39 name: plugin.name.clone(),
40 description: plugin.description.clone(),
41 version: plugin.version.clone(),
42 enabled: plugin.enabled,
43 skills: PluginComponentRef {
44 source: plugin.skills.source,
45 filter: plugin.skills.filter,
46 include: plugin.skills.include.clone(),
47 exclude: plugin.skills.exclude.clone(),
48 },
49 agents: PluginComponentRef {
50 source: plugin.agents.source,
51 filter: plugin.agents.filter,
52 include: plugin.agents.include.clone(),
53 exclude: plugin.agents.exclude.clone(),
54 },
55 mcp_servers: plugin.mcp_servers.clone(),
56 scripts: plugin.scripts.iter().map(|s| s.name.clone()).collect(),
57 keywords: plugin.keywords.clone(),
58 category: plugin.category.clone(),
59 author: plugin.author.name.clone(),
60 };
61
62 Ok(CommandOutput::card_value(
63 format!("Plugin: {}", args.id),
64 &output,
65 ))
66}
67
68fn get_plugins_path() -> Result<std::path::PathBuf> {
69 let profile = systemprompt_config::ProfileBootstrap::get().context("Failed to get profile")?;
70 Ok(std::path::PathBuf::from(profile.paths.plugins()))
71}
72
73fn parse_plugin_config(config_path: &Path) -> Result<systemprompt_models::PluginConfigFile> {
74 let content = std::fs::read_to_string(config_path)
75 .with_context(|| format!("Failed to read {}", config_path.display()))?;
76 let plugin_file: systemprompt_models::PluginConfigFile = serde_yaml::from_str(&content)
77 .with_context(|| format!("Failed to parse {}", config_path.display()))?;
78 Ok(plugin_file)
79}