malbox_plugin_sdk/lib.rs
1//! Malbox Plugin SDK
2//!
3//! This crate is the foundation for building plugins for Malbox.
4//!
5//! Plugins come in two flavors:
6//!
7//! - **Host plugins** run on the daemon and communicate over IPC. Mark your
8//! struct with [`#[malbox::host_plugin]`](macro@host_plugin).
9//! - **Guest plugins** run inside a sandboxed environment and communicate over gRPC.
10//! Mark your struct with [`#[malbox::guest_plugin]`](macro@guest_plugin).
11//!
12//! In both cases, you write handler methods and annotate them with
13//! [`#[malbox::on_task]`](macro@on_task),
14//! [`#[malbox::on_start]`](macro@on_start),
15//! [`#[malbox::on_stop]`](macro@on_stop), or
16//! [`#[malbox::on_event(...)]`](macro@on_event).
17//! The SDK generates the boilerplate: trait impls, `fn main`,
18//! runtime setup, and result transport.
19//!
20//! Package metadata (`name`, `version`, `description`, `authors`) is read
21//! automatically from your `Cargo.toml`, so you only need to specify
22//! `state` and `execution` in the attribute.
23//!
24//! # Example
25//!
26//! ```ignore
27//! extern crate malbox_plugin_sdk as malbox;
28//! use malbox::prelude::*;
29//!
30//! #[malbox::host_plugin]
31//! #[malbox(state = "persistent", execution = "parallel")]
32//! struct MyPlugin;
33//!
34//! #[malbox::handlers]
35//! impl MyPlugin {
36//! #[malbox::on_task]
37//! fn analyze(&self, ctx: &Context) -> Result<()> {
38//! Ok(())
39//! }
40//! }
41//! ```
42
43pub mod context;
44pub mod error;
45pub mod health;
46pub mod meta;
47pub mod plugin;
48pub mod report;
49pub mod result;
50pub mod runtime;
51
52#[doc(hidden)]
53pub mod internal;
54#[doc(hidden)]
55pub mod log;
56#[cfg(feature = "guest")]
57pub(crate) mod stash;
58
59#[cfg(any(test, feature = "testkit"))]
60pub mod testkit;
61
62/// Everything a plugin needs in scope. Start with `use malbox::prelude::*;`.
63pub mod prelude {
64 pub use crate::context::{Context, ResultSink, TaskInfo};
65 pub use crate::error::{Result, SdkError};
66 pub use crate::health::HealthStatus;
67 pub use crate::meta::{ExecutionContext, PluginMeta, PluginState};
68 pub use crate::plugin::{GuestPlugin, HostPlugin, LaunchResult, Plugin};
69 pub use crate::report::{
70 ArtifactRef, Block, CalloutLevel, Classification, Column, Confidence, GraphEdge, GraphNode,
71 Indicator, KvPair, PluginInfo, REPORT_RESULT_NAME, Report, ReportBuilder, SCHEMA_VERSION,
72 Section, SectionBuilder, TimelineEvent, TreeNode, Ttp, Verdict,
73 };
74 pub use crate::result::PluginResult;
75
76 pub use serde::{Deserialize, Serialize};
77 pub use tracing::{debug, error, info, warn};
78
79 pub use malbox_plugin_transport::messages::events::Event;
80}
81
82pub use malbox_plugin_macros::*;
83
84pub use context::{Context, ResultSink, TaskInfo};
85pub use error::{Result, SdkError};
86pub use health::HealthStatus;
87pub use meta::{ExecutionContext, PluginMeta, PluginState};
88pub use plugin::{GuestPlugin, HostPlugin, LaunchResult, Plugin};
89pub use report::{
90 REPORT_RESULT_NAME, Report, ReportBuilder, SCHEMA_VERSION, SectionBuilder, Verdict,
91};
92pub use result::PluginResult;