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::Mcp(mcp::McpCommands::Logs(_) | mcp::McpCommands::ListPackages(_))
55            | Self::Run(_) => CommandDescriptor::PROFILE_ONLY,
56            Self::Mcp(_) => CommandDescriptor::FULL,
57            _ => CommandDescriptor::PROFILE_ONLY.with_remote_eligible(),
58        }
59    }
60}
61
62pub async fn execute(cmd: PluginsCommands, config: &CliConfig) -> Result<()> {
63    match cmd {
64        PluginsCommands::List(args) => {
65            render_result(&list::execute(&args, config));
66            Ok(())
67        },
68        PluginsCommands::Show(args) => {
69            let result = show::execute(&args, config).context("Failed to show extension")?;
70            render_result(&result);
71            Ok(())
72        },
73        PluginsCommands::Run(args) => run::execute(args, config).await,
74        PluginsCommands::Validate(args) => {
75            render_result(&validate::execute(&args, config));
76            Ok(())
77        },
78        PluginsCommands::Config(args) => {
79            let result =
80                config::execute(&args, config).context("Failed to get extension config")?;
81            render_result(&result);
82            Ok(())
83        },
84        PluginsCommands::Capabilities(args) => {
85            capabilities::execute(args, config);
86            Ok(())
87        },
88        PluginsCommands::Mcp(cmd) => mcp::execute_with_config(cmd, config).await,
89    }
90}