Skip to main content

systemprompt_models/bridge/
plugin_bundle.rs

1//! Plugin bundle contract: the `.claude-plugin/plugin.json` manifest shape and
2//! the well-formedness predicate every consumer shares.
3//!
4//! A *plugin bundle* is the installable artifact a host (Claude Code / Cowork)
5//! reads: a directory rooted on `.claude-plugin/plugin.json` plus the component
6//! files it ships (`skills/<n>/SKILL.md`, `agents/<n>.md`, `.mcp.json`, …).
7//! [`PluginManifest`] is that manifest; [`bundle_has_manifest`] is the single
8//! definition of "is this directory a well-formed bundle?" so the gateway
9//! serve path, the bridge sync, the CLI generator, and the marketplace export
10//! never drift on the contract.
11
12use serde::{Deserialize, Serialize};
13
14pub const PLUGIN_MANIFEST_RELPATH: &str = ".claude-plugin/plugin.json";
15
16/// Manifest directory names accepted on a host, in preference order.
17///
18/// Cowork historically materialised the manifest under both the dotted and the
19/// undotted directory, so both are honoured when probing an installed bundle.
20pub const PLUGIN_MANIFEST_DIRS: &[&str] = &[".claude-plugin", "claude-plugin"];
21
22pub const PLUGIN_MANIFEST_FILE: &str = "plugin.json";
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct PluginManifest {
26    pub name: String,
27    #[serde(default)]
28    pub description: String,
29    #[serde(default)]
30    pub version: String,
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub author: Option<ManifestAuthor>,
33    #[serde(default, skip_serializing_if = "Option::is_none")]
34    pub hooks: Option<String>,
35    #[serde(default, skip_serializing_if = "Vec::is_empty")]
36    pub keywords: Vec<String>,
37    #[serde(
38        default,
39        rename = "installationPreference",
40        skip_serializing_if = "Option::is_none"
41    )]
42    pub installation_preference: Option<String>,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct ManifestAuthor {
47    pub name: String,
48    #[serde(default, skip_serializing_if = "String::is_empty")]
49    pub email: String,
50}
51
52pub fn bundle_has_manifest<S: AsRef<str>>(paths: impl IntoIterator<Item = S>) -> bool {
53    paths
54        .into_iter()
55        .any(|path| path.as_ref() == PLUGIN_MANIFEST_RELPATH)
56}