Skip to main content

systemprompt_cli/commands/plugins/capabilities/
jobs.rs

1//! `plugins capabilities jobs` command.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use clap::Args;
7
8use crate::CliConfig;
9use crate::commands::plugins::discover_registry;
10use crate::commands::plugins::types::{JobWithExtension, JobsListOutput};
11use crate::shared::CommandOutput;
12
13#[derive(Debug, Clone, Args)]
14pub struct JobsArgs {
15    #[arg(long, help = "Filter by extension ID")]
16    pub extension: Option<String>,
17
18    #[arg(long, help = "Show only enabled jobs")]
19    pub enabled: bool,
20}
21
22pub fn execute(args: &JobsArgs, _config: &CliConfig) -> CommandOutput {
23    let registry = discover_registry();
24
25    let jobs: Vec<JobWithExtension> = registry
26        .extensions()
27        .iter()
28        .filter(|ext| args.extension.as_ref().is_none_or(|f| ext.id().contains(f)))
29        .flat_map(|ext| {
30            ext.jobs()
31                .iter()
32                .filter_map(|job| {
33                    if args.enabled && !job.enabled() {
34                        return None;
35                    }
36
37                    Some(JobWithExtension {
38                        extension_id: systemprompt_identifiers::PluginId::new(ext.id()),
39                        extension_name: ext.name().to_owned(),
40                        job_name: job.name().to_owned(),
41                        schedule: job.schedule().to_owned(),
42                        enabled: job.enabled(),
43                    })
44                })
45                .collect::<Vec<_>>()
46        })
47        .collect();
48
49    let total = jobs.len();
50
51    let output = JobsListOutput { jobs, total };
52
53    CommandOutput::table_of(
54        vec!["extension_id", "job_name", "schedule", "enabled"],
55        &output.jobs,
56    )
57    .with_title("Jobs Across Extensions")
58}