chasm-cli 2.0.0

Universal chat session manager - harvest, merge, and analyze AI chat history from VS Code, Cursor, and other editors
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
// Copyright (c) 2024-2026 Nervosys LLC
// SPDX-License-Identifier: AGPL-3.0-only
//! Plugin System Module
//!
//! Provides an extensible plugin architecture for CSM:
//! - Plugin discovery and loading
//! - Plugin lifecycle management
//! - Event hooks and callbacks
//! - Configuration management
//! - Sandboxed execution

use anyhow::{anyhow, Result};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::RwLock;

// =============================================================================
// Plugin Manifest and Metadata
// =============================================================================

/// Plugin manifest (plugin.json)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginManifest {
    /// Plugin unique identifier
    pub id: String,
    /// Plugin name
    pub name: String,
    /// Plugin version (semver)
    pub version: String,
    /// Plugin description
    pub description: Option<String>,
    /// Author information
    pub author: Option<PluginAuthor>,
    /// Plugin homepage URL
    pub homepage: Option<String>,
    /// Repository URL
    pub repository: Option<String>,
    /// License identifier
    pub license: Option<String>,
    /// Minimum CSM version required
    pub csm_version: String,
    /// Plugin entry point
    pub main: String,
    /// Required permissions
    pub permissions: Vec<Permission>,
    /// Event hooks this plugin registers
    pub hooks: Vec<String>,
    /// Configuration schema
    pub config_schema: Option<serde_json::Value>,
    /// Dependencies on other plugins
    pub dependencies: Vec<PluginDependency>,
    /// Plugin category
    pub category: PluginCategory,
    /// Keywords for discovery
    pub keywords: Vec<String>,
}

/// Plugin author information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginAuthor {
    pub name: String,
    pub email: Option<String>,
    pub url: Option<String>,
}

/// Plugin dependency
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginDependency {
    /// Dependency plugin ID
    pub id: String,
    /// Version requirement (semver range)
    pub version: String,
    /// Whether dependency is optional
    pub optional: bool,
}

/// Plugin category
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PluginCategory {
    /// Provider integration
    Provider,
    /// Export format
    Export,
    /// Analysis/insights
    Analysis,
    /// UI enhancement
    Ui,
    /// Automation
    Automation,
    /// Storage backend
    Storage,
    /// Authentication
    Auth,
    /// Other
    Other,
}

/// Plugin permission
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Permission {
    /// Read session data
    SessionRead,
    /// Write/modify session data
    SessionWrite,
    /// Delete sessions
    SessionDelete,
    /// Read configuration
    ConfigRead,
    /// Write configuration
    ConfigWrite,
    /// Network access
    Network,
    /// File system access (within plugin directory)
    FileSystem,
    /// Execute shell commands (restricted)
    Shell,
    /// Access sensitive data (encryption keys, etc.)
    Sensitive,
    /// Background execution
    Background,
    /// System notifications
    Notifications,
}

// =============================================================================
// Plugin Instance and State
// =============================================================================

/// Plugin state
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PluginState {
    /// Plugin is loaded but not activated
    Loaded,
    /// Plugin is active and running
    Active,
    /// Plugin is disabled
    Disabled,
    /// Plugin encountered an error
    Error,
    /// Plugin is being updated
    Updating,
}

/// Plugin instance
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginInstance {
    /// Plugin manifest
    pub manifest: PluginManifest,
    /// Current state
    pub state: PluginState,
    /// Installation path
    pub path: PathBuf,
    /// Installed at timestamp
    pub installed_at: DateTime<Utc>,
    /// Last activated timestamp
    pub last_activated: Option<DateTime<Utc>>,
    /// Plugin configuration
    pub config: serde_json::Value,
    /// Error message if in error state
    pub error: Option<String>,
    /// Usage statistics
    pub stats: PluginStats,
}

/// Plugin usage statistics
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct PluginStats {
    /// Number of times activated
    pub activation_count: u64,
    /// Total execution time (milliseconds)
    pub total_execution_ms: u64,
    /// Number of errors
    pub error_count: u64,
    /// Last error timestamp
    pub last_error: Option<DateTime<Utc>>,
}

// =============================================================================
// Plugin Events and Hooks
// =============================================================================

/// Event that plugins can hook into
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PluginEvent {
    /// Session created
    SessionCreated { session_id: String },
    /// Session updated
    SessionUpdated { session_id: String },
    /// Session deleted
    SessionDeleted { session_id: String },
    /// Session imported
    SessionImported { session_id: String, provider: String },
    /// Session exported
    SessionExported { session_id: String, format: String },
    /// Harvest completed
    HarvestCompleted { session_count: usize, provider: String },
    /// Sync completed
    SyncCompleted { direction: String, changes: usize },
    /// User action
    UserAction { action: String, context: serde_json::Value },
    /// Application startup
    AppStartup,
    /// Application shutdown
    AppShutdown,
    /// Configuration changed
    ConfigChanged { key: String },
    /// Custom event
    Custom { name: String, data: serde_json::Value },
}

/// Hook registration
#[derive(Debug, Clone)]
pub struct HookRegistration {
    /// Plugin ID
    pub plugin_id: String,
    /// Event type pattern
    pub event_pattern: String,
    /// Priority (lower = higher priority)
    pub priority: i32,
    /// Handler ID
    pub handler_id: String,
}

/// Result of a hook invocation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HookResult {
    /// Plugin ID
    pub plugin_id: String,
    /// Success status
    pub success: bool,
    /// Result data
    pub data: Option<serde_json::Value>,
    /// Error message if failed
    pub error: Option<String>,
    /// Execution time (ms)
    pub execution_ms: u64,
}

// =============================================================================
// Plugin API Context
// =============================================================================

/// API context provided to plugins
pub struct PluginContext {
    /// Plugin ID
    pub plugin_id: String,
    /// Granted permissions
    pub permissions: Vec<Permission>,
    /// Plugin data directory
    pub data_dir: PathBuf,
    /// Plugin configuration
    pub config: serde_json::Value,
}

impl PluginContext {
    /// Check if plugin has a permission
    pub fn has_permission(&self, permission: &Permission) -> bool {
        self.permissions.contains(permission)
    }

    /// Get plugin data path
    pub fn get_data_path(&self, filename: &str) -> PathBuf {
        self.data_dir.join(filename)
    }

    /// Read plugin data file
    pub fn read_data(&self, filename: &str) -> Result<String> {
        if !self.has_permission(&Permission::FileSystem) {
            return Err(anyhow!("Permission denied: FileSystem"));
        }
        let path = self.get_data_path(filename);
        Ok(std::fs::read_to_string(path)?)
    }

    /// Write plugin data file
    pub fn write_data(&self, filename: &str, content: &str) -> Result<()> {
        if !self.has_permission(&Permission::FileSystem) {
            return Err(anyhow!("Permission denied: FileSystem"));
        }
        std::fs::create_dir_all(&self.data_dir)?;
        let path = self.get_data_path(filename);
        Ok(std::fs::write(path, content)?)
    }
}

// =============================================================================
// Plugin Manager
// =============================================================================

/// Plugin manager handles plugin lifecycle
pub struct PluginManager {
    /// Plugins directory
    plugins_dir: PathBuf,
    /// Loaded plugins
    plugins: Arc<RwLock<HashMap<String, PluginInstance>>>,
    /// Registered hooks
    hooks: Arc<RwLock<Vec<HookRegistration>>>,
    /// Plugin configurations
    configs: Arc<RwLock<HashMap<String, serde_json::Value>>>,
}

impl PluginManager {
    /// Create a new plugin manager
    pub fn new(plugins_dir: PathBuf) -> Self {
        Self {
            plugins_dir,
            plugins: Arc::new(RwLock::new(HashMap::new())),
            hooks: Arc::new(RwLock::new(Vec::new())),
            configs: Arc::new(RwLock::new(HashMap::new())),
        }
    }

    /// Initialize the plugin manager
    pub async fn init(&self) -> Result<()> {
        std::fs::create_dir_all(&self.plugins_dir)?;
        self.discover_plugins().await?;
        Ok(())
    }

    /// Discover and load plugins
    pub async fn discover_plugins(&self) -> Result<Vec<String>> {
        let mut discovered = Vec::new();
        
        if !self.plugins_dir.exists() {
            return Ok(discovered);
        }
        
        for entry in std::fs::read_dir(&self.plugins_dir)? {
            let entry = entry?;
            let path = entry.path();
            
            if path.is_dir() {
                let manifest_path = path.join("plugin.json");
                if manifest_path.exists() {
                    match self.load_plugin(&path).await {
                        Ok(plugin_id) => discovered.push(plugin_id),
                        Err(e) => {
                            log::warn!("Failed to load plugin at {:?}: {}", path, e);
                        }
                    }
                }
            }
        }
        
        Ok(discovered)
    }

    /// Load a plugin from a directory
    pub async fn load_plugin(&self, plugin_path: &PathBuf) -> Result<String> {
        let manifest_path = plugin_path.join("plugin.json");
        let manifest_content = std::fs::read_to_string(&manifest_path)?;
        let manifest: PluginManifest = serde_json::from_str(&manifest_content)?;
        
        // Validate manifest
        self.validate_manifest(&manifest)?;
        
        // Check dependencies
        self.check_dependencies(&manifest).await?;
        
        let instance = PluginInstance {
            manifest: manifest.clone(),
            state: PluginState::Loaded,
            path: plugin_path.clone(),
            installed_at: Utc::now(),
            last_activated: None,
            config: serde_json::Value::Object(serde_json::Map::new()),
            error: None,
            stats: PluginStats::default(),
        };
        
        let plugin_id = manifest.id.clone();
        self.plugins.write().await.insert(plugin_id.clone(), instance);
        
        log::info!("Loaded plugin: {} v{}", manifest.name, manifest.version);
        Ok(plugin_id)
    }

    /// Validate plugin manifest
    fn validate_manifest(&self, manifest: &PluginManifest) -> Result<()> {
        // Validate ID format
        if manifest.id.is_empty() || manifest.id.len() > 64 {
            return Err(anyhow!("Invalid plugin ID"));
        }
        
        // Validate version (semver)
        if semver::Version::parse(&manifest.version).is_err() {
            return Err(anyhow!("Invalid version format: {}", manifest.version));
        }
        
        // Validate CSM version requirement
        let current_version = env!("CARGO_PKG_VERSION");
        let req = semver::VersionReq::parse(&manifest.csm_version)
            .map_err(|_| anyhow!("Invalid csm_version: {}", manifest.csm_version))?;
        let current = semver::Version::parse(current_version)?;
        
        if !req.matches(&current) {
            return Err(anyhow!(
                "Plugin requires CSM {}, but current version is {}",
                manifest.csm_version,
                current_version
            ));
        }
        
        Ok(())
    }

    /// Check plugin dependencies
    async fn check_dependencies(&self, manifest: &PluginManifest) -> Result<()> {
        let plugins = self.plugins.read().await;
        
        for dep in &manifest.dependencies {
            if dep.optional {
                continue;
            }
            
            let plugin = plugins.get(&dep.id);
            match plugin {
                None => {
                    return Err(anyhow!("Missing required dependency: {}", dep.id));
                }
                Some(p) => {
                    let req = semver::VersionReq::parse(&dep.version)?;
                    let ver = semver::Version::parse(&p.manifest.version)?;
                    if !req.matches(&ver) {
                        return Err(anyhow!(
                            "Dependency {} version {} does not match requirement {}",
                            dep.id, p.manifest.version, dep.version
                        ));
                    }
                }
            }
        }
        
        Ok(())
    }

    /// Activate a plugin
    pub async fn activate(&self, plugin_id: &str) -> Result<()> {
        let mut plugins = self.plugins.write().await;
        let plugin = plugins.get_mut(plugin_id)
            .ok_or_else(|| anyhow!("Plugin not found: {}", plugin_id))?;
        
        if plugin.state == PluginState::Active {
            return Ok(());
        }
        
        // Register hooks
        for hook in &plugin.manifest.hooks {
            self.register_hook(plugin_id, hook, 0).await?;
        }
        
        plugin.state = PluginState::Active;
        plugin.last_activated = Some(Utc::now());
        plugin.stats.activation_count += 1;
        
        log::info!("Activated plugin: {}", plugin_id);
        Ok(())
    }

    /// Deactivate a plugin
    pub async fn deactivate(&self, plugin_id: &str) -> Result<()> {
        let mut plugins = self.plugins.write().await;
        let plugin = plugins.get_mut(plugin_id)
            .ok_or_else(|| anyhow!("Plugin not found: {}", plugin_id))?;
        
        // Unregister hooks
        self.unregister_hooks(plugin_id).await?;
        
        plugin.state = PluginState::Disabled;
        
        log::info!("Deactivated plugin: {}", plugin_id);
        Ok(())
    }

    /// Uninstall a plugin
    pub async fn uninstall(&self, plugin_id: &str) -> Result<()> {
        // Deactivate first
        self.deactivate(plugin_id).await.ok();
        
        let mut plugins = self.plugins.write().await;
        let plugin = plugins.remove(plugin_id)
            .ok_or_else(|| anyhow!("Plugin not found: {}", plugin_id))?;
        
        // Remove plugin directory
        if plugin.path.exists() {
            std::fs::remove_dir_all(&plugin.path)?;
        }
        
        log::info!("Uninstalled plugin: {}", plugin_id);
        Ok(())
    }

    /// Register a hook
    async fn register_hook(&self, plugin_id: &str, event_pattern: &str, priority: i32) -> Result<()> {
        let mut hooks = self.hooks.write().await;
        hooks.push(HookRegistration {
            plugin_id: plugin_id.to_string(),
            event_pattern: event_pattern.to_string(),
            priority,
            handler_id: uuid::Uuid::new_v4().to_string(),
        });
        Ok(())
    }

    /// Unregister all hooks for a plugin
    async fn unregister_hooks(&self, plugin_id: &str) -> Result<()> {
        let mut hooks = self.hooks.write().await;
        hooks.retain(|h| h.plugin_id != plugin_id);
        Ok(())
    }

    /// Emit an event to all registered hooks
    pub async fn emit(&self, event: PluginEvent) -> Vec<HookResult> {
        let hooks = self.hooks.read().await;
        let plugins = self.plugins.read().await;
        let mut results = Vec::new();
        
        let event_name = self.get_event_name(&event);
        
        // Sort hooks by priority
        let mut matching_hooks: Vec<_> = hooks.iter()
            .filter(|h| self.matches_pattern(&h.event_pattern, &event_name))
            .collect();
        matching_hooks.sort_by_key(|h| h.priority);
        
        for hook in matching_hooks {
            let _plugin = match plugins.get(&hook.plugin_id) {
                Some(p) if p.state == PluginState::Active => p,
                _ => continue,
            };
            
            let start = std::time::Instant::now();
            
            // In a real implementation, this would call the plugin's handler
            // For now, we just record the invocation
            let result = HookResult {
                plugin_id: hook.plugin_id.clone(),
                success: true,
                data: Some(serde_json::json!({
                    "event": event_name,
                    "handled": true
                })),
                error: None,
                execution_ms: start.elapsed().as_millis() as u64,
            };
            
            results.push(result);
        }
        
        results
    }

    fn get_event_name(&self, event: &PluginEvent) -> String {
        match event {
            PluginEvent::SessionCreated { .. } => "session.created".to_string(),
            PluginEvent::SessionUpdated { .. } => "session.updated".to_string(),
            PluginEvent::SessionDeleted { .. } => "session.deleted".to_string(),
            PluginEvent::SessionImported { .. } => "session.imported".to_string(),
            PluginEvent::SessionExported { .. } => "session.exported".to_string(),
            PluginEvent::HarvestCompleted { .. } => "harvest.completed".to_string(),
            PluginEvent::SyncCompleted { .. } => "sync.completed".to_string(),
            PluginEvent::UserAction { action, .. } => format!("user.{}", action),
            PluginEvent::AppStartup => "app.startup".to_string(),
            PluginEvent::AppShutdown => "app.shutdown".to_string(),
            PluginEvent::ConfigChanged { .. } => "config.changed".to_string(),
            PluginEvent::Custom { name, .. } => format!("custom.{}", name),
        }
    }

    fn matches_pattern(&self, pattern: &str, event_name: &str) -> bool {
        if pattern == "*" {
            return true;
        }
        if let Some(prefix) = pattern.strip_suffix("*") {
            return event_name.starts_with(prefix);
        }
        pattern == event_name
    }

    /// Get plugin instance
    pub async fn get_plugin(&self, plugin_id: &str) -> Option<PluginInstance> {
        self.plugins.read().await.get(plugin_id).cloned()
    }

    /// List all plugins
    pub async fn list_plugins(&self) -> Vec<PluginInstance> {
        self.plugins.read().await.values().cloned().collect()
    }

    /// Get plugin configuration
    pub async fn get_config(&self, plugin_id: &str) -> Option<serde_json::Value> {
        self.plugins.read().await
            .get(plugin_id)
            .map(|p| p.config.clone())
    }

    /// Set plugin configuration
    pub async fn set_config(&self, plugin_id: &str, config: serde_json::Value) -> Result<()> {
        let mut plugins = self.plugins.write().await;
        let plugin = plugins.get_mut(plugin_id)
            .ok_or_else(|| anyhow!("Plugin not found: {}", plugin_id))?;
        
        // Validate against schema if present
        if let Some(schema) = &plugin.manifest.config_schema {
            self.validate_config(&config, schema)?;
        }
        
        plugin.config = config;
        Ok(())
    }

    fn validate_config(&self, _config: &serde_json::Value, _schema: &serde_json::Value) -> Result<()> {
        // In a real implementation, use JSON Schema validation
        Ok(())
    }

    /// Create plugin context
    pub async fn create_context(&self, plugin_id: &str) -> Result<PluginContext> {
        let plugins = self.plugins.read().await;
        let plugin = plugins.get(plugin_id)
            .ok_or_else(|| anyhow!("Plugin not found: {}", plugin_id))?;
        
        Ok(PluginContext {
            plugin_id: plugin_id.to_string(),
            permissions: plugin.manifest.permissions.clone(),
            data_dir: plugin.path.join("data"),
            config: plugin.config.clone(),
        })
    }
}

// =============================================================================
// Plugin Registry (for discovery/installation)
// =============================================================================

/// Plugin registry entry
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegistryEntry {
    /// Plugin ID
    pub id: String,
    /// Latest version
    pub version: String,
    /// Plugin name
    pub name: String,
    /// Description
    pub description: String,
    /// Author
    pub author: String,
    /// Download URL
    pub download_url: String,
    /// Download count
    pub downloads: u64,
    /// Rating (0-5)
    pub rating: f32,
    /// Category
    pub category: PluginCategory,
    /// Keywords
    pub keywords: Vec<String>,
    /// Updated at
    pub updated_at: DateTime<Utc>,
}

/// Plugin registry client
pub struct PluginRegistry {
    /// Registry URL
    registry_url: String,
}

impl PluginRegistry {
    pub fn new(registry_url: String) -> Self {
        Self { registry_url }
    }

    /// Search for plugins
    pub async fn search(&self, _query: &str, _category: Option<PluginCategory>) -> Result<Vec<RegistryEntry>> {
        // In a real implementation, this would make an HTTP request
        // For now, return empty results
        Ok(Vec::new())
    }

    /// Get plugin details
    pub async fn get_plugin(&self, plugin_id: &str) -> Result<RegistryEntry> {
        Err(anyhow!("Plugin not found in registry: {}", plugin_id))
    }

    /// Download and install plugin
    pub async fn install(&self, plugin_id: &str, manager: &PluginManager) -> Result<()> {
        let _entry = self.get_plugin(plugin_id).await?;
        
        // Download plugin
        let plugin_dir = manager.plugins_dir.join(plugin_id);
        std::fs::create_dir_all(&plugin_dir)?;
        
        // In a real implementation, download and extract the plugin
        // For now, just create the directory
        
        manager.load_plugin(&plugin_dir).await?;
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use tempfile::tempdir;

    #[tokio::test]
    async fn test_plugin_manager_init() {
        let temp_dir = tempdir().unwrap();
        let manager = PluginManager::new(temp_dir.path().to_path_buf());
        
        assert!(manager.init().await.is_ok());
    }

    #[test]
    fn test_event_name() {
        let manager = PluginManager::new(PathBuf::from("."));
        
        let event = PluginEvent::SessionCreated { session_id: "test".to_string() };
        assert_eq!(manager.get_event_name(&event), "session.created");
    }

    #[test]
    fn test_pattern_matching() {
        let manager = PluginManager::new(PathBuf::from("."));
        
        assert!(manager.matches_pattern("*", "session.created"));
        assert!(manager.matches_pattern("session.*", "session.created"));
        assert!(manager.matches_pattern("session.created", "session.created"));
        assert!(!manager.matches_pattern("session.updated", "session.created"));
    }
}