Skip to content

Commit b42e672

Browse files
echobtfactorydroid
andauthored
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

18 files changed

+7546
-789
lines changed

Cargo.lock

Lines changed: 1071 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cortex-plugins/Cargo.toml

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
11
[package]
22
name = "cortex-plugins"
3-
version = "0.1.0"
4-
edition = "2021"
5-
description = "Plugin system for Cortex CLI"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
authors.workspace = true
7+
license.workspace = true
8+
repository.workspace = true
9+
description = "Complete WASM-based plugin system for Cortex CLI"
610

711
[dependencies]
8-
tokio = { version = "1", features = ["full"] }
9-
serde = { version = "1", features = ["derive"] }
10-
serde_json = "1"
11-
tracing = "0.1"
12-
thiserror = "1"
13-
async-trait = "0.1"
14-
dirs = "5"
12+
# Async runtime
13+
tokio = { workspace = true }
14+
15+
# Serialization
16+
serde = { workspace = true }
17+
serde_json = { workspace = true }
18+
toml = { workspace = true }
19+
20+
# Error handling
21+
thiserror = { workspace = true }
22+
anyhow = { workspace = true }
23+
24+
# Logging
25+
tracing = { workspace = true }
26+
27+
# Async traits
28+
async-trait = { workspace = true }
29+
30+
# Utilities
31+
dirs = { workspace = true }
32+
uuid = { workspace = true }
33+
chrono = { workspace = true }
34+
semver = "1.0"
35+
sha2 = { workspace = true }
36+
hex = { workspace = true }
37+
38+
# WASM Runtime
39+
wasmtime = { version = "29", features = ["async", "component-model"] }
40+
wasmtime-wasi = { version = "29" }
41+
42+
# HTTP client for plugin network access
43+
reqwest = { workspace = true }
44+
45+
# URL parsing
46+
url = { workspace = true }
47+
48+
# File watching for hot-reload
49+
notify = { workspace = true }
50+
51+
# Concurrent data structures
52+
dashmap = { workspace = true }
53+
parking_lot = { workspace = true }
54+
55+
[dev-dependencies]
56+
tempfile = { workspace = true }
57+
tokio-test = { workspace = true }

0 commit comments

Comments
 (0)