lean_ctx/core/addons/mod.rs
1//! Addon ecosystem: community extensions for lean-ctx (#858).
2//!
3//! An **addon** packages an external MCP server (+ metadata) behind a small
4//! [`lean-ctx-addon.toml`](manifest) manifest, so a third-party tool plugs into
5//! lean-ctx's MCP gateway with a single `lean-ctx addon add` — no fork, no
6//! recompile. Addons are user-global and reuse the gateway trust model
7//! (`[gateway]` is global-only and opt-in; see [`crate::core::gateway`]).
8//!
9//! Layers:
10//! - [`manifest`] — the `lean-ctx-addon.toml` contract (also the registry entry shape).
11//! - [`registry`] — the curated catalog (bundled, with optional user override).
12//! - [`store`] — what is installed locally (`<data_dir>/addons/installed.json`).
13//! - [`install`] — wires an addon into the gateway and records it in the store.
14//! - [`bootstrap`] — `[install]` block executor: provisions an addon's upstream
15//! package via a pinned package manager (uv/pip/cargo/npm/brew/dotnet) on `add`,
16//! uninstalls it on `remove` (#1105, Phase 2). Never goes through a shell.
17//! - [`scaffold`] — `addon init` starter manifest generator (DX, P4).
18//!
19//! Security (#863, P1):
20//! - [`capabilities`] — the declared `[capabilities]` permission model that
21//! drives the per-addon sandbox + env allowlist + install consent.
22//! - [`trust`] — trust tier (`verified`) + static risk assessment of the wiring.
23//! - [`audit`] — capability-coherence + malware heuristics + the verified/paid
24//! gate (#403): does the declared `[capabilities]` match the wiring, and is the
25//! wiring free of malicious patterns?
26//! - [`commerce`] — sellable-addon model (`[pricing]`) + the mandatory paid
27//! listing gate (Track B): no addon is sold without clearing the audit.
28//! - [`binhash`] — SHA-256 binary pinning for stdio addons (refuse a swapped
29//! executable at spawn).
30//! - [`policy`] — the global-only `[addons]` install policy floor + the gate.
31//! - [`signing`] — Ed25519 signing for the user-override registry.
32//! - [`revocation`] — central kill-switch that blocks a revoked addon from
33//! running (install, catalog build, every proxy call).
34//! - [`integrity`] — install-time wiring hash + local re-verify (the lockfile).
35//! - [`meter`] — per-addon / per-tool usage metering (analytics + billing base, P5).
36//! - [`sandbox`] — per-addon OS sandbox for spawned stdio servers.
37//! - [`runtime`] — redaction + audit of untrusted addon tool output.
38//!
39//! Grammar addons (#690) are a separate, smaller concept living alongside
40//! this module rather than inside it — a long-tail tree-sitter grammar is a
41//! `cdylib` `dlopen`'d directly into lean-ctx's own process, not an MCP
42//! server, so none of the subprocess/gateway-shaped layers above apply:
43//! - [`grammar_manifest`] — the grammar-addon manifest (language, extensions,
44//! per-platform dylib + mandatory SHA-256 pin, tree-sitter ABI version).
45//! - [`grammar_registry`] — its bundled/local-override catalog, reusing only
46//! [`signing`] and [`binhash`] from the MCP addon machinery.
47//! - `grammar_install` (internal) — zero-config fetch (#690, Phase 1d): downloads a
48//! missing pinned dylib on first use, silent on any failure (offline,
49//! network error, hash mismatch) so it degrades to the regex-signature
50//! fallback exactly like "not installed" — no `addon add` consent step,
51//! since a grammar addon is a parsing fallback, not a spawned process.
52
53pub mod audit;
54pub mod binhash;
55pub mod bootstrap;
56pub mod capabilities;
57pub mod commerce;
58pub mod env_scrub;
59// Grammar addons only matter to a build that can dlopen a Language into a
60// tree-sitter parser at all — dead weight in the no-tree-sitter slim build
61// (#663), so gated the same way `core::signatures_ts` is.
62#[cfg(feature = "tree-sitter")]
63pub(crate) mod grammar_install;
64#[cfg(feature = "tree-sitter")]
65pub mod grammar_manifest;
66#[cfg(feature = "tree-sitter")]
67pub mod grammar_registry;
68pub mod health;
69pub mod install;
70pub mod integrity;
71pub mod manifest;
72pub mod meter;
73pub mod policy;
74pub mod registry;
75pub mod revocation;
76pub mod runtime;
77pub mod sandbox;
78pub mod scaffold;
79pub mod signing;
80pub mod store;
81pub mod trust;
82
83pub use audit::{AuditReport, AuditVerdict};
84pub use bootstrap::{AddonInstall, BootstrapStatus, InstallReceipt, Manager};
85pub use capabilities::{AddonCapabilities, FilesystemAccess, NetworkAccess};
86pub use commerce::{AddonPricing, PaidGate, PricingModel, paid_listing_gate};
87#[cfg(feature = "tree-sitter")]
88pub use grammar_manifest::{GrammarAsset, GrammarManifest};
89pub use health::ProbeReport;
90pub use manifest::{AddonManifest, AddonMcp, AddonMeta};
91pub use policy::{AddonPolicy, AddonsConfig};
92pub use sandbox::SandboxMode;
93pub use store::{InstalledAddon, InstalledStore};
94pub use trust::{RiskFinding, RiskLevel, TrustTier};