Skip to main content

sh_layer4/
types.rs

1//! # Layer 4 Core Types
2//!
3//! Layer 4 使用的核心类型定义。
4
5use serde::{Deserialize, Serialize};
6use thiserror::Error;
7
8/// Layer 4 统一 Result 类型
9pub type Layer4Result<T> = anyhow::Result<T>;
10
11/// Layer 4 错误类型
12#[derive(Debug, Error)]
13pub enum Layer4Error {
14    #[error("Channel error: {0}")]
15    Channel(String),
16
17    #[error("Plugin error: {0}")]
18    Plugin(String),
19
20    #[error("Worktree error: {0}")]
21    Worktree(String),
22
23    #[error("Git error: {0}")]
24    Git(String),
25
26    #[error("Configuration error: {0}")]
27    Config(String),
28
29    #[error("IO error: {0}")]
30    Io(#[from] std::io::Error),
31
32    #[error("Serialization error: {0}")]
33    Serialization(#[from] serde_json::Error),
34
35    #[error("Not found: {0}")]
36    NotFound(String),
37
38    #[error("Already exists: {0}")]
39    AlreadyExists(String),
40
41    #[error("Invalid state: {0}")]
42    InvalidState(String),
43}
44
45/// 集成层配置
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct IntegrationConfig {
48    pub plugin_dir: String,
49    pub worktrees_dir: String,
50    pub channel_timeout_ms: u64,
51    pub max_plugins: usize,
52    pub max_worktrees: usize,
53}
54
55impl Default for IntegrationConfig {
56    fn default() -> Self {
57        Self {
58            plugin_dir: "~/.continuum/plugins".to_string(),
59            worktrees_dir: ".claude/worktrees".to_string(),
60            channel_timeout_ms: 30000,
61            max_plugins: 50,
62            max_worktrees: 10,
63        }
64    }
65}
66
67/// 消息优先级
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
69pub enum MessagePriority {
70    Low,
71    #[default]
72    Normal,
73    High,
74    Urgent,
75}
76
77/// 插件权限
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct PluginPermission {
80    pub can_read_files: bool,
81    pub can_write_files: bool,
82    pub can_execute_commands: bool,
83    pub can_access_network: bool,
84    pub allowed_paths: Vec<String>,
85    pub allowed_commands: Vec<String>,
86}
87
88impl Default for PluginPermission {
89    fn default() -> Self {
90        Self {
91            can_read_files: true,
92            can_write_files: false,
93            can_execute_commands: false,
94            can_access_network: false,
95            allowed_paths: Vec::new(),
96            allowed_commands: Vec::new(),
97        }
98    }
99}
100
101#[cfg(test)]
102mod tests {
103    use super::*;
104
105    #[test]
106    fn test_integration_config_default() {
107        let config = IntegrationConfig::default();
108        assert_eq!(config.max_plugins, 50);
109        assert_eq!(config.max_worktrees, 10);
110    }
111
112    #[test]
113    fn test_plugin_permission_default() {
114        let perm = PluginPermission::default();
115        assert!(perm.can_read_files);
116        assert!(!perm.can_write_files);
117    }
118
119    #[test]
120    fn test_message_priority_default() {
121        let priority = MessagePriority::default();
122        assert_eq!(priority, MessagePriority::Normal);
123    }
124}