smooth_plugin/plugin.rs
1use async_trait::async_trait;
2
3use crate::command::PluginCommand;
4
5/// The core Plugin trait. Implement this to extend Smooth.
6///
7/// Plugins can register CLI subcommands, API routes, and smooth-operator tools.
8/// Each plugin has a unique identifier, a human-readable name, and a version string.
9/// Lifecycle hooks (`init` / `shutdown`) are called once at startup and shutdown.
10#[async_trait]
11pub trait Plugin: Send + Sync {
12 /// Unique plugin identifier (e.g., "smooai", "jira", "linear")
13 fn id(&self) -> &str;
14
15 /// Human-readable name
16 fn name(&self) -> &str;
17
18 /// Version string
19 fn version(&self) -> &str;
20
21 /// Called once at startup.
22 ///
23 /// # Errors
24 /// Returns an error if initialization fails.
25 async fn init(&self) -> anyhow::Result<()> {
26 Ok(())
27 }
28
29 /// Called on shutdown.
30 ///
31 /// # Errors
32 /// Returns an error if shutdown cleanup fails.
33 async fn shutdown(&self) -> anyhow::Result<()> {
34 Ok(())
35 }
36
37 /// Register CLI subcommands (returns command definitions).
38 fn commands(&self) -> Vec<PluginCommand> {
39 vec![]
40 }
41
42 /// Register API routes (returns axum Router to be nested).
43 fn routes(&self) -> Option<axum::Router> {
44 None
45 }
46
47 /// Register smooth-operator tools.
48 fn tools(&self) -> Vec<Box<dyn smooth_operator::tool::Tool>> {
49 vec![]
50 }
51}