Skip to main content

systemprompt_cli/commands/plugins/
mod.rs

1pub mod types;
2
3mod capabilities;
4mod config;
5mod list;
6mod run;
7mod show;
8mod validate;
9
10pub mod mcp;
11
12use anyhow::{Context, Result};
13use clap::Subcommand;
14use systemprompt_extension::ExtensionRegistry;
15
16use crate::CliConfig;
17use crate::descriptor::{CommandDescriptor, DescribeCommand};
18use crate::shared::render_result;
19
20fn discover_registry() -> ExtensionRegistry {
21    ExtensionRegistry::discover().unwrap_or_else(|e| {
22        tracing::error!(error = %e, "extension dependency cycle; using empty registry");
23        ExtensionRegistry::new()
24    })
25}
26
27#[derive(Debug, Subcommand)]
28pub enum PluginsCommands {
29    #[command(about = "List all discovered extensions")]
30    List(list::ListArgs),
31
32    #[command(about = "Show detailed extension information")]
33    Show(show::ShowArgs),
34
35    #[command(about = "Run a CLI extension command", trailing_var_arg = true)]
36    Run(run::RunArgs),
37
38    #[command(about = "Validate extension dependencies and configurations")]
39    Validate(validate::ValidateArgs),
40
41    #[command(about = "Show extension configuration")]
42    Config(config::ConfigArgs),
43
44    #[command(about = "List capabilities across all extensions")]
45    Capabilities(capabilities::CapabilitiesArgs),
46
47    #[command(subcommand, about = "MCP server management")]
48    Mcp(mcp::McpCommands),
49}
50
51impl DescribeCommand for PluginsCommands {
52    fn descriptor(&self) -> CommandDescriptor {
53        match self {
54            Self::Run(_) => CommandDescriptor::PROFILE_ONLY,
55            Self::Mcp(_) => CommandDescriptor::FULL,
56            _ => CommandDescriptor::PROFILE_ONLY.with_remote_eligible(),
57        }
58    }
59}
60
61pub async fn execute(cmd: PluginsCommands, config: &CliConfig) -> Result<()> {
62    match cmd {
63        PluginsCommands::List(args) => {
64            render_result(&list::execute(&args, config));
65            Ok(())
66        },
67        PluginsCommands::Show(args) => {
68            let result = show::execute(&args, config).context("Failed to show extension")?;
69            render_result(&result);
70            Ok(())
71        },
72        PluginsCommands::Run(args) => run::execute(args, config).await,
73        PluginsCommands::Validate(args) => {
74            render_result(&validate::execute(&args, config));
75            Ok(())
76        },
77        PluginsCommands::Config(args) => {
78            let result =
79                config::execute(&args, config).context("Failed to get extension config")?;
80            render_result(&result);
81            Ok(())
82        },
83        PluginsCommands::Capabilities(args) => {
84            capabilities::execute(args, config);
85            Ok(())
86        },
87        PluginsCommands::Mcp(cmd) => mcp::execute_with_config(cmd, config).await,
88    }
89}