feat(plugin): lift host surface behind a HostApi trait (phase 1b)

Plugins targeted the host's concrete HostSession type. Add a HostApi
trait in ocs_plugin_api behind an optional `host` feature (the only thing
that pulls acadrust, so the core crate stays dependency-free). HostSession
implements it and BuiltinPlugin::dispatch now takes `&mut dyn HostApi`, so
an out-of-tree add-on compiles against the contract crate alone. Per-tab
plugin state is reached through object-safe plugin_state* helpers.

Completes the phase-1 host-surface extraction in the #100 epic.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 4.8 committed 2026-06-17 11:31:05 +03:00
1 parent 96ec672d5b
commit 5ccf5cfe36
12 files changed
+231 -22

No files matched your search

+8 -3
View File
@@ -1,6 +1,9 @@
// Plugin traits — HostSession lives in `app::plugin_host` (same-crate field access).
// Plugin traits — HostSession lives in `app::plugin_host` (same-crate field
// access) and implements the stable `HostApi` contract plugins target.
pub(crate) use crate::app::plugin_host::HostSession;
/// The stable runtime surface a plugin's `dispatch` receives.
pub use ocs_plugin_api::host::HostApi;
use crate::modules::CadModule;
@@ -9,9 +12,11 @@ use super::manifest::PluginManifest;
/// Add-on package entry point (phase 1: in-tree, in-process).
///
/// One `PluginRegistration` per package — ribbon tab, manifest, and command
/// dispatch are owned here. See `docs/plugin-architecture.md`.
/// dispatch are owned here. `dispatch` receives `&mut dyn HostApi` (the stable
/// `ocs_plugin_api` contract), not the host's concrete session type. See
/// `docs/plugin-architecture.md`.
pub trait BuiltinPlugin: Send + Sync {
fn manifest(&self) -> &'static PluginManifest;
fn ribbon(&self) -> Box<dyn CadModule>;
fn dispatch(&self, host: &mut HostSession<'_>, cmd: &str) -> bool;
fn dispatch(&self, host: &mut dyn HostApi, cmd: &str) -> bool;
}