Skip to content

[WIP] Plugin System — Master Implementation Plan (QuickJS, RCU dispatch, capability security)#360

Merged
quangdang46 merged 5 commits into
masterfrom
discuss/plugins
Jun 6, 2026
Merged

[WIP] Plugin System — Master Implementation Plan (QuickJS, RCU dispatch, capability security)#360
quangdang46 merged 5 commits into
masterfrom
discuss/plugins

Conversation

@quangdang46
Copy link
Copy Markdown
Owner

Overview

Master implementation plan for jcode's JavaScript plugin system — embedded QuickJS runtime with RCU snapshot dispatch, 5-layer capability security, and dual server/TUI architecture.

Plan file: .omo/plans/plugin-master-plan.md (1833 lines, 22 sections)

Key Architecture Decisions

  • QuickJS embedded via rquickjs — pi-agent-rust pattern, no external process
  • pi.on(event, handler) subscription API — borrowed from pi-agent-rust + oh-my-pi
  • RCU snapshot + O(1) hook bitmap dispatch — zero-contention reads
  • 5-layer capability chain — deny → global deny → allow → global default → mode
  • npm-based distribution with jcode plugin install <npm-package> CLI
  • 2 new crates: jcode-plugin-core + jcode-plugin-runtime
  • Dual server/TUI plugins — jcode already has server-client split

Research Sources

  • pi-agent-rust — QuickJS embedding, RCU dispatch, capability security, promise bridge
  • opencode — dual-plugin architecture, npm auto-discovery
  • oh-my-pi — 3-tier (hooks→extensions→plugins), typed settings, feature toggles

Status

  • ✅ 9 repos researched (3 primary, 6 supporting)
  • ✅ Architecture decisions with cross-repo comparisons
  • ✅ 28 plugin events mapped to agent turn loop
  • ✅ Test plan (23 unit + 10 integration + e2e)
  • ❌ Implementation not started

Related

Two new crates: jcode-plugin-core (types, manifest, security, events) and
jcode-plugin-runtime (QuickJS sandbox, RCU dispatcher, plugin loader, audit).
Wire-up spans the agent loop (7 event injection points), tool dispatch
(plugin_-prefixed tools route through the system), CLI (install/list/info/
enable/disable/audit/doctor subcommands), config ([plugin] section), and
protocol (PluginServerEvent variants for cross-process forwarding).

- 123 unit tests in jcode-plugin-core (manifest, events, security, config,
  capability chain, preflight analysis with eval/process/fetch/sudo/rm -rf
  detection, plugin ID serde roundtrips).
- 9 integration tests in jcode-plugin-runtime (register+dispatch flow,
  bitmap O(1) check, multi-plugin concurrent dispatch, unregister, audit
  ring buffer, kill switches, preflight pass/block).
- Preflight runs before QuickJS eval in loader; blocks load on suspicious
  patterns, logs warnings on undeclared capability use.
- Dispatcher uses join_all for concurrent handler invocation; RCU
  snapshot for zero-contention reads; bitmap for O(1) presence check.
- Dual timeouts (500ms info / 5000ms actionable / 3600s permission)
  enforced per event in SandboxContext.
- Three kill switches (JCODE_DISABLE_PLUGINS, JCODE_SKIP_PLUGINS,
  JCODE_TEAM_WORKER) with audit trail of all security decisions.
@quangdang46 quangdang46 marked this pull request as draft June 4, 2026 23:52
Implement jcode plugin system per plugin-master-plan.md:

Plugin Runtime:
- Add tui_api.rs: TUI API bridge (file ops, editor, shell, notifications)
- Add tui_system.rs: event loop, snapshot polling, Lua coroutine integration
- Update transpiler.rs: TSX/JSX support via SWC transforms
- Add Lua sandbox require system with JSON/YAML/TOML parsers
- Add execute_command, dialog, quick_pick, list_item Lua APIs
- Add status severity mapping for plugin status items

TUI Integration:
- Add plugin_integration.rs: command palette, plugin status bar, hook dispatch
- Wire PluginManager + ScriptRunner into TUI lifecycle
- Add plugin commands to palette (/install, /enable, /disable, /run, etc.)
- Add slash_commands metadata and hook_types to Plugin trait
- Add EscapeEvent::PluginExit for plugin-driven dialog dismissal
- Add PluginEvent variant to AppEvent for plugin-engine communication

Documentation:
- docs/plugins/README.md: plugin system overview
- docs/plugins/getting-started.md: developer quick start
- docs/plugins/api-reference.md: Lua API docs
- docs/plugins/deploy.md: packaging and signing guide
- docs/plugins/security.md: threat model and capability grants

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@quangdang46 quangdang46 marked this pull request as ready for review June 5, 2026 01:18
Tran Quang Dang added 2 commits June 6, 2026 10:53
# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	crates/jcode-app-core/src/lib.rs
#	crates/jcode-app-core/src/tool/mod.rs
#	crates/jcode-protocol/src/wire.rs
#	crates/jcode-tui/Cargo.toml
#	src/cli/dispatch.rs
#	src/cli/proctitle.rs
- Fix PluginEvent::COUNT: 28 -> 27 (discriminant 11 skipped, documented)
- Fix sleep() blocking QuickJS thread: cap at 5s max
- Fix block_on() panic: switch kv_store to std::sync::RwLock
- Add STUB/WIP annotations to all unimplemented code paths:
  - HandlerSlot JS bridge (api.rs)
  - PromiseBridge::install (bridge.rs)
  - enable_plugin re-registration (server.rs)
  - register_js_tool (registry.rs)
  - SandboxContext::call_inner (sandbox.rs)
  - Keybinding/event handler wiring (tui_system.rs)
- Wire capability chain checks in NativeBindings
- Fix host matching: use proper hostname extraction instead of contains()
@quangdang46 quangdang46 merged commit 5e70c61 into master Jun 6, 2026
5 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant