sen-plugin-host 0.8.1

Wasm plugin host runtime for sen-rs CLI framework
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
//! Plugin registry with hot reload support
//!
//! Provides a thread-safe registry for managing loaded plugins with
//! support for dynamic addition, removal, and updates.
//!
//! # Permission System Integration
//!
//! The registry supports an optional permission system for capability-based
//! access control. When enabled, plugins are checked against their declared
//! capabilities before execution.
//!
//! ```rust,ignore
//! use sen_plugin_host::{PluginRegistry, PermissionPresets};
//!
//! // With permission checking
//! let config = PermissionPresets::interactive("myapp")?;
//! let registry = PluginRegistry::with_permissions(config)?;
//!
//! // Execution will check capabilities and prompt if needed
//! registry.execute("hello", &["World"]).await?;
//! ```

use crate::audit::{self, TrustLevel};
use crate::permission::{
    PermissionConfig, PermissionContext, PermissionDecision, StoredPermission, StoredTrustLevel,
};
use crate::{LoadedPlugin, LoaderError, PluginLoader};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use tokio::sync::RwLock;

/// A thread-safe registry for managing loaded plugins
#[derive(Clone)]
pub struct PluginRegistry {
    inner: Arc<RwLock<RegistryInner>>,
    loader: Arc<PluginLoader>,
    permission: Option<Arc<PermissionConfig>>,
}

struct RegistryInner {
    /// Plugins indexed by command name
    plugins: HashMap<String, PluginEntry>,
    /// Map from file path to command name for reload tracking
    path_to_command: HashMap<PathBuf, String>,
}

struct PluginEntry {
    plugin: LoadedPlugin,
    source_path: Option<PathBuf>,
}

impl PluginRegistry {
    /// Create a new empty plugin registry
    pub fn new() -> Result<Self, LoaderError> {
        Ok(Self {
            inner: Arc::new(RwLock::new(RegistryInner {
                plugins: HashMap::new(),
                path_to_command: HashMap::new(),
            })),
            loader: Arc::new(PluginLoader::new()?),
            permission: None,
        })
    }

    /// Create with an existing loader
    pub fn with_loader(loader: PluginLoader) -> Self {
        Self {
            inner: Arc::new(RwLock::new(RegistryInner {
                plugins: HashMap::new(),
                path_to_command: HashMap::new(),
            })),
            loader: Arc::new(loader),
            permission: None,
        }
    }

    /// Create with permission configuration
    ///
    /// When permission config is set, the registry will check plugin
    /// capabilities before execution and prompt users as needed.
    pub fn with_permissions(config: PermissionConfig) -> Result<Self, LoaderError> {
        Ok(Self {
            inner: Arc::new(RwLock::new(RegistryInner {
                plugins: HashMap::new(),
                path_to_command: HashMap::new(),
            })),
            loader: Arc::new(PluginLoader::new()?),
            permission: Some(Arc::new(config)),
        })
    }

    /// Add permission configuration to an existing registry
    pub fn set_permissions(&mut self, config: PermissionConfig) {
        self.permission = Some(Arc::new(config));
    }

    /// Load and register a plugin from a file path
    pub async fn load_plugin(&self, path: impl AsRef<Path>) -> Result<String, LoaderError> {
        let path = path.as_ref();
        let wasm_bytes = tokio::fs::read(path).await.map_err(|e| {
            LoaderError::MemoryAccess(format!("Failed to read file {}: {}", path.display(), e))
        })?;

        let plugin = self.loader.load(&wasm_bytes)?;
        let command_name = plugin.manifest.command.name.clone();

        let mut inner = self.inner.write().await;

        // Remove old mapping if exists
        if let Some(old_cmd) = inner.path_to_command.remove(path) {
            inner.plugins.remove(&old_cmd);
        }

        // Add new mappings
        inner
            .path_to_command
            .insert(path.to_path_buf(), command_name.clone());
        inner.plugins.insert(
            command_name.clone(),
            PluginEntry {
                plugin,
                source_path: Some(path.to_path_buf()),
            },
        );

        tracing::info!(command = %command_name, path = %path.display(), "Plugin loaded");
        Ok(command_name)
    }

    /// Register a pre-loaded plugin (without file path tracking)
    pub async fn register(&self, plugin: LoadedPlugin) -> String {
        let command_name = plugin.manifest.command.name.clone();

        let mut inner = self.inner.write().await;
        inner.plugins.insert(
            command_name.clone(),
            PluginEntry {
                plugin,
                source_path: None,
            },
        );

        tracing::info!(command = %command_name, "Plugin registered");
        command_name
    }

    /// Unload a plugin by file path
    pub async fn unload_by_path(&self, path: impl AsRef<Path>) -> Option<String> {
        let path = path.as_ref();
        let mut inner = self.inner.write().await;

        if let Some(command_name) = inner.path_to_command.remove(path) {
            inner.plugins.remove(&command_name);
            tracing::info!(command = %command_name, path = %path.display(), "Plugin unloaded");
            Some(command_name)
        } else {
            None
        }
    }

    /// Unload a plugin by command name
    pub async fn unload(&self, command_name: &str) -> bool {
        let mut inner = self.inner.write().await;

        if let Some(entry) = inner.plugins.remove(command_name) {
            if let Some(path) = entry.source_path {
                inner.path_to_command.remove(&path);
            }
            tracing::info!(command = %command_name, "Plugin unloaded");
            true
        } else {
            false
        }
    }

    /// Reload a plugin from its source path
    pub async fn reload_by_path(&self, path: impl AsRef<Path>) -> Result<String, LoaderError> {
        self.load_plugin(path).await
    }

    /// Get a list of all registered command names
    pub async fn list_commands(&self) -> Vec<String> {
        let inner = self.inner.read().await;
        inner.plugins.keys().cloned().collect()
    }

    /// Check if a command exists
    pub async fn has_command(&self, command_name: &str) -> bool {
        let inner = self.inner.read().await;
        inner.plugins.contains_key(command_name)
    }

    /// Execute a plugin command
    ///
    /// If permission configuration is set, this will:
    /// 1. Check stored permissions for the plugin
    /// 2. Apply the permission strategy to decide allow/deny/prompt
    /// 3. Prompt the user if needed (for interactive mode)
    /// 4. Record audit events
    /// 5. Execute the plugin if permitted
    pub async fn execute(
        &self,
        command_name: &str,
        args: &[String],
    ) -> Result<sen_plugin_api::ExecuteResult, RegistryError> {
        let mut inner = self.inner.write().await;

        let entry = inner
            .plugins
            .get_mut(command_name)
            .ok_or_else(|| RegistryError::CommandNotFound(command_name.to_string()))?;

        // Check permissions if configured
        if let Some(ref perm_config) = self.permission {
            let capabilities = &entry.plugin.manifest.capabilities;

            // Record permission request audit event
            let _ = perm_config
                .audit
                .record(audit::permission_requested(command_name, capabilities));

            // Get stored permission
            let key =
                perm_config
                    .store
                    .make_key(command_name, None, perm_config.strategy.granularity());
            let stored = perm_config.store.get(&key).ok().flatten();

            // Build context for strategy
            let ctx = PermissionContext {
                plugin_name: command_name,
                command_path: &[],
                requested: capabilities,
                granted: stored.as_ref().map(|s| &s.capabilities),
                interactive: perm_config.prompt.is_interactive(),
            };

            // Check for escalation
            let decision = if let Some(ref stored_perm) = stored {
                if stored_perm.has_escalated(capabilities) {
                    // Record escalation audit event
                    let _ = perm_config.audit.record(audit::escalation_detected(
                        command_name,
                        &stored_perm.capabilities,
                        capabilities,
                    ));
                    perm_config.strategy.on_escalation(&ctx)
                } else {
                    perm_config.strategy.check(&ctx)
                }
            } else {
                perm_config.strategy.check(&ctx)
            };

            // Handle decision
            match decision {
                PermissionDecision::Allow => {
                    let _ = perm_config.audit.record(audit::permission_granted(
                        command_name,
                        capabilities,
                        TrustLevel::Permanent,
                    ));
                }
                PermissionDecision::Deny(reason) => {
                    let _ = perm_config.audit.record(audit::permission_denied(
                        command_name,
                        capabilities,
                        &reason,
                    ));
                    return Err(RegistryError::PermissionDenied {
                        plugin: command_name.to_string(),
                        reason,
                    });
                }
                PermissionDecision::Prompt => {
                    // Prompt user
                    let prompt_result = if let Some(ref stored_perm) = stored {
                        perm_config.prompt.prompt_escalation(
                            command_name,
                            &stored_perm.capabilities,
                            capabilities,
                        )
                    } else {
                        perm_config.prompt.prompt(command_name, capabilities)
                    };

                    match prompt_result {
                        Ok(result) if result.is_allowed() => {
                            // Store permission if should persist
                            if result.should_persist() {
                                let trust_level =
                                    result.to_trust_level().unwrap_or(StoredTrustLevel::Session);
                                let stored_perm =
                                    StoredPermission::new(capabilities.clone(), trust_level);
                                let _ = perm_config.store.set(&key, stored_perm);
                            }

                            let audit_trust = match result.to_trust_level() {
                                Some(StoredTrustLevel::Permanent) => TrustLevel::Permanent,
                                Some(StoredTrustLevel::Session) => TrustLevel::Session,
                                None => TrustLevel::Once,
                            };
                            let _ = perm_config.audit.record(audit::permission_granted(
                                command_name,
                                capabilities,
                                audit_trust,
                            ));
                        }
                        Ok(_) | Err(_) => {
                            let _ = perm_config.audit.record(audit::permission_denied(
                                command_name,
                                capabilities,
                                "User denied permission",
                            ));
                            return Err(RegistryError::PermissionDenied {
                                plugin: command_name.to_string(),
                                reason: "User denied permission".to_string(),
                            });
                        }
                    }
                }
                PermissionDecision::AllowPartial(_reduced) => {
                    // For now, treat partial as full allow
                    // Future: could pass reduced capabilities to plugin
                    let _ = perm_config.audit.record(audit::permission_granted(
                        command_name,
                        capabilities,
                        TrustLevel::Once,
                    ));
                }
            }
        }

        entry
            .plugin
            .instance
            .execute(args)
            .map_err(RegistryError::Execution)
    }

    /// Get plugin manifest for a command
    pub async fn get_manifest(&self, command_name: &str) -> Option<sen_plugin_api::PluginManifest> {
        let inner = self.inner.read().await;
        inner
            .plugins
            .get(command_name)
            .map(|e| e.plugin.manifest.clone())
    }

    /// Get all plugin manifests
    pub async fn get_all_manifests(&self) -> Vec<sen_plugin_api::PluginManifest> {
        let inner = self.inner.read().await;
        inner
            .plugins
            .values()
            .map(|e| e.plugin.manifest.clone())
            .collect()
    }

    /// Get the number of loaded plugins
    pub async fn len(&self) -> usize {
        let inner = self.inner.read().await;
        inner.plugins.len()
    }

    /// Check if the registry is empty
    pub async fn is_empty(&self) -> bool {
        let inner = self.inner.read().await;
        inner.plugins.is_empty()
    }
}

/// Errors that can occur during registry operations
#[derive(Debug, thiserror::Error)]
pub enum RegistryError {
    #[error("Command not found: {0}")]
    CommandNotFound(String),

    #[error("Plugin execution failed: {0}")]
    Execution(#[source] LoaderError),

    #[error("Permission denied for plugin '{plugin}': {reason}")]
    PermissionDenied { plugin: String, reason: String },
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::audit::MemoryAuditSink;
    use crate::permission::{
        AutoPromptHandler, MemoryPermissionStore, PermissionPresets, PermissionStore, PromptResult,
        RecordingPromptHandler,
    };

    const HELLO_PLUGIN_WASM: &[u8] = include_bytes!(
        "../../examples/hello-plugin/target/wasm32-unknown-unknown/release/hello_plugin.wasm"
    );

    // ========================================================================
    // Basic Registry Tests (without permissions)
    // ========================================================================

    #[tokio::test]
    async fn test_registry_register_and_execute() {
        let registry = PluginRegistry::new().unwrap();
        let loader = PluginLoader::new().unwrap();
        let plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();

        let cmd = registry.register(plugin).await;
        assert_eq!(cmd, "hello");
        assert!(registry.has_command("hello").await);

        let result = registry
            .execute("hello", &["World".to_string()])
            .await
            .unwrap();
        match result {
            sen_plugin_api::ExecuteResult::Success(output) => {
                assert_eq!(output, "Hello, World!");
            }
            _ => panic!("Expected success"),
        }
    }

    #[tokio::test]
    async fn test_registry_unload() {
        let registry = PluginRegistry::new().unwrap();
        let loader = PluginLoader::new().unwrap();
        let plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();

        registry.register(plugin).await;
        assert!(registry.has_command("hello").await);

        registry.unload("hello").await;
        assert!(!registry.has_command("hello").await);
    }

    #[tokio::test]
    async fn test_registry_list_commands() {
        let registry = PluginRegistry::new().unwrap();
        let loader = PluginLoader::new().unwrap();
        let plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();

        registry.register(plugin).await;

        let commands = registry.list_commands().await;
        assert_eq!(commands, vec!["hello"]);
    }

    // ========================================================================
    // Permission Integration Tests
    // ========================================================================

    #[tokio::test]
    async fn test_registry_with_permissions_trust_all() {
        // TrustAll strategy should allow execution without prompts
        let config = PermissionPresets::trust_all_dangerous();
        let registry = PluginRegistry::with_permissions(config).unwrap();

        let loader = PluginLoader::new().unwrap();
        let plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();
        registry.register(plugin).await;

        let result = registry
            .execute("hello", &["World".to_string()])
            .await
            .unwrap();

        match result {
            sen_plugin_api::ExecuteResult::Success(output) => {
                assert_eq!(output, "Hello, World!");
            }
            _ => panic!("Expected success with trust_all"),
        }
    }

    #[tokio::test]
    async fn test_registry_with_permissions_testing_preset() {
        // Testing preset uses auto-approve, should allow execution
        let config = PermissionPresets::testing();
        let registry = PluginRegistry::with_permissions(config).unwrap();

        let loader = PluginLoader::new().unwrap();
        let plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();
        registry.register(plugin).await;

        let result = registry
            .execute("hello", &["World".to_string()])
            .await
            .unwrap();

        match result {
            sen_plugin_api::ExecuteResult::Success(output) => {
                assert_eq!(output, "Hello, World!");
            }
            _ => panic!("Expected success with testing preset"),
        }
    }

    #[tokio::test]
    async fn test_registry_with_permissions_deny_on_prompt() {
        // Custom config with auto-deny prompt handler
        let config = PermissionConfig::new(
            crate::permission::DefaultPermissionStrategy,
            MemoryPermissionStore::new(),
            AutoPromptHandler::always_deny(),
            crate::audit::NullAuditSink,
            crate::permission::TrustFlagConfig::default(),
        );

        let registry = PluginRegistry::with_permissions(config).unwrap();

        let loader = PluginLoader::new().unwrap();
        let mut plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();

        // Add capabilities to trigger permission check
        plugin.manifest.capabilities = sen_plugin_api::Capabilities::default()
            .with_stdio(sen_plugin_api::StdioCapability::stdout_only());

        registry.register(plugin).await;

        let result = registry.execute("hello", &["World".to_string()]).await;

        match result {
            Err(RegistryError::PermissionDenied { plugin, reason }) => {
                assert_eq!(plugin, "hello");
                assert!(reason.contains("denied"));
            }
            Ok(_) => panic!("Expected PermissionDenied error"),
            Err(e) => panic!("Unexpected error: {:?}", e),
        }
    }

    #[tokio::test]
    async fn test_registry_with_permissions_audit_logging() {
        // Verify audit events are recorded
        let audit_sink = std::sync::Arc::new(MemoryAuditSink::new());

        let config = PermissionConfig {
            strategy: std::sync::Arc::new(crate::permission::DefaultPermissionStrategy),
            store: std::sync::Arc::new(MemoryPermissionStore::new()),
            prompt: std::sync::Arc::new(AutoPromptHandler::always_allow()),
            audit: audit_sink.clone(),
            trust_flags: crate::permission::TrustFlagConfig::default(),
        };

        let registry = PluginRegistry::with_permissions(config).unwrap();

        let loader = PluginLoader::new().unwrap();
        let mut plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();
        plugin.manifest.capabilities = sen_plugin_api::Capabilities::default()
            .with_stdio(sen_plugin_api::StdioCapability::stdout_only());

        registry.register(plugin).await;
        let _ = registry.execute("hello", &["World".to_string()]).await;

        // Verify audit events were recorded
        let events = audit_sink.events();
        assert!(!events.is_empty(), "Should have audit events");

        // Should have at least a permission request event
        let request_events =
            audit_sink.find_by_type(crate::audit::AuditEventType::PermissionRequested);
        assert!(
            !request_events.is_empty(),
            "Should have permission request event"
        );
    }

    #[tokio::test]
    async fn test_registry_with_permissions_stores_grant() {
        // Verify that granted permissions are stored
        let store = std::sync::Arc::new(MemoryPermissionStore::new());

        let config = PermissionConfig {
            strategy: std::sync::Arc::new(crate::permission::DefaultPermissionStrategy),
            store: store.clone(),
            prompt: std::sync::Arc::new(AutoPromptHandler::always_allow()),
            audit: std::sync::Arc::new(crate::audit::NullAuditSink),
            trust_flags: crate::permission::TrustFlagConfig::default(),
        };

        let registry = PluginRegistry::with_permissions(config).unwrap();

        let loader = PluginLoader::new().unwrap();
        let mut plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();
        plugin.manifest.capabilities = sen_plugin_api::Capabilities::default()
            .with_stdio(sen_plugin_api::StdioCapability::stdout_only());

        registry.register(plugin).await;
        let _ = registry.execute("hello", &["World".to_string()]).await;

        // Verify permission was stored
        let stored = store.get("hello").unwrap();
        assert!(stored.is_some(), "Permission should be stored after grant");
    }

    #[tokio::test]
    async fn test_registry_with_permissions_prompt_recording() {
        // Verify prompts are triggered correctly
        let prompt_handler =
            std::sync::Arc::new(RecordingPromptHandler::new(PromptResult::AllowAlways));

        let config = PermissionConfig {
            strategy: std::sync::Arc::new(crate::permission::DefaultPermissionStrategy),
            store: std::sync::Arc::new(MemoryPermissionStore::new()),
            prompt: prompt_handler.clone(),
            audit: std::sync::Arc::new(crate::audit::NullAuditSink),
            trust_flags: crate::permission::TrustFlagConfig::default(),
        };

        let registry = PluginRegistry::with_permissions(config).unwrap();

        let loader = PluginLoader::new().unwrap();
        let mut plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();
        plugin.manifest.capabilities = sen_plugin_api::Capabilities::default()
            .with_stdio(sen_plugin_api::StdioCapability::stdout_only());

        registry.register(plugin).await;
        let _ = registry.execute("hello", &["World".to_string()]).await;

        // Verify prompt was called
        assert_eq!(
            prompt_handler.prompt_count(),
            1,
            "Should have prompted once"
        );
        let prompts = prompt_handler.prompts();
        assert_eq!(prompts[0].plugin, "hello");
    }

    #[tokio::test]
    async fn test_registry_without_permissions_skips_check() {
        // Registry without permission config should skip all checks
        let registry = PluginRegistry::new().unwrap();

        let loader = PluginLoader::new().unwrap();
        let mut plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();

        // Even with capabilities declared, no check should happen
        plugin.manifest.capabilities = sen_plugin_api::Capabilities::default()
            .with_fs_read(vec![sen_plugin_api::PathPattern::new("/")]);

        registry.register(plugin).await;

        // Should execute without any permission checks
        let result = registry
            .execute("hello", &["World".to_string()])
            .await
            .unwrap();

        match result {
            sen_plugin_api::ExecuteResult::Success(output) => {
                assert_eq!(output, "Hello, World!");
            }
            _ => panic!("Expected success without permission config"),
        }
    }

    #[tokio::test]
    async fn test_registry_empty_capabilities_allowed() {
        // Plugins with no capabilities should be allowed without prompt
        let prompt_handler = std::sync::Arc::new(RecordingPromptHandler::new(PromptResult::Deny));

        let config = PermissionConfig {
            strategy: std::sync::Arc::new(crate::permission::DefaultPermissionStrategy),
            store: std::sync::Arc::new(MemoryPermissionStore::new()),
            prompt: prompt_handler.clone(),
            audit: std::sync::Arc::new(crate::audit::NullAuditSink),
            trust_flags: crate::permission::TrustFlagConfig::default(),
        };

        let registry = PluginRegistry::with_permissions(config).unwrap();

        let loader = PluginLoader::new().unwrap();
        let plugin = loader.load(HELLO_PLUGIN_WASM).unwrap();
        // Default capabilities are empty

        registry.register(plugin).await;
        let result = registry.execute("hello", &["World".to_string()]).await;

        // Should succeed without prompting (empty caps = no permissions needed)
        assert!(result.is_ok(), "Empty capabilities should be allowed");
        assert_eq!(
            prompt_handler.prompt_count(),
            0,
            "Should not prompt for empty caps"
        );
    }
}