Commit b42e672
feat(plugins): Implement complete WASM-based plugin system (#495)
* feat(plugins): Implement complete WASM-based plugin system
This PR implements a comprehensive plugin system for Cortex CLI that allows
users to create custom plugins in WebAssembly (WASM) using Rust.
## Features
### Plugin Architecture
- WASM runtime using wasmtime v29 for sandboxed plugin execution
- Plugin manifest system (plugin.toml) with capabilities, permissions, commands, and hooks
- Complete plugin lifecycle management (discover, load, init, shutdown, unload)
### Plugin API
- File system access (read/write with permission controls)
- Shell command execution (with allowed commands list)
- HTTP requests (with domain restrictions)
- Configuration and storage APIs
- Logging and notifications
### Hook System
- tool.execute.before: Intercept and modify tool arguments
- tool.execute.after: Post-process tool results
- chat.message: Process chat messages
- permission.ask: Override permission decisions
### Event System
- Session events (start/end)
- Tool execution events
- Plugin lifecycle events
- Custom plugin events
### TUI Integration
- Enhanced /plugins command with subcommands:
- /plugins list - List installed plugins
- /plugins info <id> - Show plugin details
- /plugins enable/disable <id> - Toggle plugins
- /plugins install/uninstall - Manage plugins
- /plugins create <name> - Scaffold new plugin
### Plugin SDK
- Template for plugin manifest (plugin.toml)
- Rust code template for WASM plugins
- Cargo.toml template with wasm32-wasi target
- PluginDev::scaffold() for generating plugin projects
## Files Changed
### New Files (cortex-plugins/src/)
- error.rs: Plugin error types
- manifest.rs: TOML manifest parsing and validation
- config.rs: Plugin configuration
- plugin.rs: Plugin trait and types
- events.rs: Event bus system
- hooks.rs: Hook registry and dispatcher
- commands.rs: Plugin command registry
- api.rs: Plugin host functions
- runtime.rs: WASM runtime with wasmtime
- loader.rs: Plugin discovery and loading
- registry.rs: Plugin registry
- manager.rs: Main plugin manager
- sdk.rs: Plugin development SDK
### Modified Files
- cortex-plugins/Cargo.toml: Added wasmtime, tokio, reqwest dependencies
- cortex-plugins/src/lib.rs: Re-exports and module structure
- cortex-tui/src/commands/registry.rs: Enhanced /plugins command
- cortex-tui/src/commands/executor.rs: Plugin command handlers
## Testing
- All 41 cortex-plugins tests pass
- All 159 cortex-tui command tests pass
- cargo clippy passes with no warnings
* feat(plugins): Add comprehensive VSCode-like hook system with 24+ hook types
This commit dramatically enhances the plugin system to be comparable to VSCode plugins
with comprehensive event hooks and interception capabilities.
New Hook Types Added:
- Prompt Injection: PromptInjectHook for AI prompt modification
- AI Response: AiResponseBeforeHook, AiResponseStreamHook, AiResponseAfterHook
- File Operations: FileOperationBeforeHook/AfterHook with deny capability
- Command Execution: CommandExecuteBeforeHook/AfterHook with output replacement
- Input Interception: InputInterceptHook with autocomplete and text expansion
- Error Handling: ErrorHandleHook with recovery actions
- Config Changes: ConfigChangedHook with pattern matching
- Session Lifecycle: SessionStartHook, SessionEndHook with context injection
- Workspace: WorkspaceChangedHook with project type detection
- Clipboard: ClipboardCopyHook, ClipboardPasteHook
- UI Rendering: UiRenderHook for custom widgets
- Focus Changes: FocusChangeHook for app focus events
Event System Expansion (13 → 40+ events):
- Session: SessionResumed
- Tool: ToolExecutionAborted
- AI: AiResponseStarted, AiResponseChunk, AiResponseCompleted, AiResponseError
- File: FileCreated, FileDeleted, FileRenamed
- Command: CommandStarted, CommandCompleted
- Config: AgentChanged
- Workspace: WorkspaceChanged, ProjectDetected
- Plugin: PluginInitialized, PluginDisabled, PluginEnabled, PluginMessage
- Error: ErrorOccurred
- Clipboard: ClipboardCopy, ClipboardPaste
- Focus: FocusGained, FocusLost
- Permission: PermissionRequested, PermissionGranted, PermissionDenied
Key Features:
- All hooks support priority ordering for execution order control
- Pattern matching for targeted hook triggers
- Flow control: Continue/Skip/Abort/Replace for all hooks
- Inter-plugin communication via PluginMessage event
- Complete Input/Output type system with proper serialization
- Full backward compatibility with existing plugin code
---------
Co-authored-by: Droid Agent <droid@factory.ai>1 parent 0d83858 commit b42e672
File tree
18 files changed
+7546
-789
lines changed- cortex-plugins
- src
- cortex-tui/src/commands
18 files changed
+7546
-789
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 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 | + | |
0 commit comments