Skip to main content

vtcode_core/plugins/
mod.rs

1//! Plugin system for VT Code
2//!
3//! This module provides a comprehensive plugin system that supports:
4//! - Commands (slash commands)
5//! - Agents (specialized profiles)
6//! - Skills (model-invoked capabilities)
7//! - Hooks (event handlers)
8//! - MCP servers (Model Context Protocol)
9
10pub mod caching;
11pub mod components;
12pub mod directory;
13pub mod loader;
14pub mod manager;
15pub mod manifest;
16pub mod runtime;
17pub mod validation;
18
19pub use caching::*;
20pub use components::*;
21pub use directory::*;
22pub use loader::*;
23pub use manager::*;
24pub use manifest::*;
25pub use runtime::*;
26pub use validation::*;
27
28crate::id_newtype::define_id_newtype! {
29    /// Identifier for a plugin.
30    pub struct PluginId
31}
32
33/// Type alias for plugin names
34pub type PluginName = String;
35
36/// Plugin loading result
37pub type PluginResult<T> = Result<T, PluginError>;
38
39pub(crate) fn validate_plugin_component(value: &str) -> PluginResult<()> {
40    let mut components = std::path::Path::new(value).components();
41    if value.trim().is_empty()
42        || !matches!(components.next(), Some(std::path::Component::Normal(_)))
43        || components.next().is_some()
44    {
45        return Err(PluginError::LoadingError(format!("Plugin name must be one normal path component: {value}")));
46    }
47    Ok(())
48}
49
50/// Plugin error types
51#[derive(Debug, thiserror::Error)]
52pub enum PluginError {
53    #[error("Plugin manifest validation failed: {0}")]
54    ManifestValidationError(String),
55
56    #[error("Plugin not found: {0}")]
57    NotFound(PluginId),
58
59    #[error("Plugin already exists: {0}")]
60    AlreadyExists(PluginId),
61
62    #[error("Plugin loading failed: {0}")]
63    LoadingError(String),
64
65    #[error("Plugin execution failed: {0}")]
66    ExecutionError(String),
67
68    #[error("Plugin permission denied: {0}")]
69    PermissionDenied(String),
70
71    #[error("Plugin configuration error: {0}")]
72    ConfigurationError(String),
73
74    #[error("I/O error: {0}")]
75    IoError(#[from] std::io::Error),
76
77    #[error("JSON serialization error: {0}")]
78    JsonError(#[from] serde_json::Error),
79
80    #[error("TOML serialization error: {0}")]
81    TomlError(#[from] toml::de::Error),
82}