systemprompt-extension 0.74.0

Compile-time extension framework for systemprompt.io AI governance infrastructure. Built on the inventory crate — registers schemas, API routes, jobs, and providers in the MCP governance pipeline.
Documentation
//! Extension discovery that builds the `ExtensionRegistry` from `inventory`
//! submissions.
//!
//! Copyright (c) systemprompt.io — Business Source License 1.1.
//! See <https://systemprompt.io> for licensing details.

use super::{ExtensionRegistration, ExtensionRegistry};
use crate::error::LoaderError;
use tracing::{debug, warn};

impl ExtensionRegistry {
    pub fn discover() -> Result<Self, LoaderError> {
        let mut registry = Self::new();

        debug!("Starting extension discovery via inventory");

        for ext in inventory::iter::<ExtensionRegistration> {
            let ext_arc = (ext.factory)();
            let ext_id = ext_arc.id().to_owned();
            let ext_name = ext_arc.name();
            debug!(
                id = %ext_id,
                name = %ext_name,
                priority = ext_arc.priority(),
                "Discovered extension via inventory"
            );
            registry.insert(ext_arc)?;
        }

        registry.sort_by_priority()?;

        let extension_names: Vec<_> = registry
            .sorted_extensions
            .iter()
            .map(|e| e.name())
            .collect();

        if registry.is_empty() {
            warn!(
                "No extensions discovered via inventory. This may indicate LTO stripped the \
                 inventory registrations, or no extensions were registered with \
                 register_extension!(). Check that extension crates are linked and #[used] \
                 attributes are present if using LTO."
            );
        } else {
            debug!(
                count = registry.len(),
                extensions = ?extension_names,
                "Extension discovery completed"
            );
        }

        Ok(registry)
    }
}