返回 CodeWhale
lib.rs
根目录 / crates / plugins / src / lib.rs
1 pub mod activation;
2 pub mod agent_plugin;
3 pub mod builtin;
4 pub mod composition_review;
5 pub mod composition_scope;
6 pub mod context;
7 pub mod discovery;
8 pub mod export;
9 pub mod host_services;
10 pub mod install;
11 pub mod managed_policy;
12 pub mod manifest;
13 pub mod marketplace;
14 pub mod matcher;
15 pub mod mutation;
16 pub mod native_presets;
17 pub mod providers;
18 pub mod recommend;
19 pub mod registry;
20 pub mod runtime;
21 pub mod types;
22
23 #[cfg(test)]
24 mod host_service_tests;
25 #[cfg(any(test, feature = "test-support"))]
26 pub mod test_fixture;
27 #[cfg(test)]
28 mod tests;
29
30 use std::collections::BTreeMap;
31
32 pub use context::{HostEnvironment, PluginDiscoveryContext};
33 pub use discovery::PluginCatalogStamp;
34 pub use registry::PluginRegistry;
35
36 pub const PLUGIN_RELOAD_NUDGE: &str =
37 "Plugins changed on disk. They apply when the session is idle, or run /plugin reload.";
38
39 pub const PLUGIN_PROVIDER_NEW_SESSION_NOTICE: &str =
40 "Plugin provider changes apply in a new session.";
41
42 fn active_provider_declarations(
43 registry: &PluginRegistry,
44 ) -> BTreeMap<String, (String, Vec<String>)> {
45 registry
46 .active_plugins()
47 .into_iter()
48 .filter(|plugin| !plugin.manifest.providers.is_empty())
49 .map(|plugin| {
50 (
51 plugin.id.as_str().to_string(),
52 (
53 plugin.content_hash.clone(),
54 plugin.manifest.providers.keys().cloned().collect(),
55 ),
56 )
57 })
58 .collect()
59 }
60
61 #[must_use]
62 pub fn provider_declarations_changed(before: &PluginRegistry, after: &PluginRegistry) -> bool {
63 active_provider_declarations(before) != active_provider_declarations(after)
64 }
65
66 /// Returns the reload nudge once per distinct on-disk catalog stamp.
67 #[must_use]
68 pub fn plugin_reload_nudge(
69 registry: &PluginRegistry,
70 last_nudged: &mut Option<PluginCatalogStamp>,
71 ) -> Option<&'static str> {
72 if !registry.on_disk_catalog_changed() {
73 return None;
74 }
75 let live = registry.live_catalog_stamp();
76 if last_nudged.as_ref() == Some(&live) {
77 return None;
78 }
79 *last_nudged = Some(live);
80 Some(PLUGIN_RELOAD_NUDGE)
81 }
82
82 lines RUST