Skip to main content

fetchium_core/plugin/
manifest.rs

1//! Plugin manifest — `plugin.toml` parser (PRD §29).
2
3use crate::error::FetchiumError;
4use serde::{Deserialize, Serialize};
5
6/// Parsed contents of a `plugin.toml` manifest file.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct PluginManifest {
9    pub name: String,
10    pub version: String,
11    /// One of: backend, extractor, ranker, formatter, validator, ai_provider
12    pub plugin_type: String,
13    /// One of: native, wasm, builtin
14    pub runtime: String,
15    pub description: String,
16    pub author: Option<String>,
17    pub homepage: Option<String>,
18    pub config_schema: Option<serde_json::Value>,
19}
20
21impl PluginManifest {
22    /// Load and parse a `plugin.toml` file.
23    pub fn load(path: &std::path::Path) -> Result<Self, FetchiumError> {
24        let content = std::fs::read_to_string(path)?;
25        toml::from_str(&content)
26            .map_err(|e| FetchiumError::Config(format!("plugin.toml parse error: {e}")))
27    }
28
29    /// Write a scaffold `plugin.toml` to the given path.
30    pub fn scaffold(
31        name: &str,
32        plugin_type: &str,
33        path: &std::path::Path,
34    ) -> Result<(), FetchiumError> {
35        let manifest = PluginManifest {
36            name: name.to_string(),
37            version: "0.1.0".to_string(),
38            plugin_type: plugin_type.to_string(),
39            runtime: "native".to_string(),
40            description: format!("A Fetchium {plugin_type} plugin"),
41            author: None,
42            homepage: None,
43            config_schema: None,
44        };
45        let content = toml::to_string_pretty(&manifest)
46            .map_err(|e| FetchiumError::Config(format!("serialise error: {e}")))?;
47        std::fs::write(path, content)?;
48        Ok(())
49    }
50}