Merge PR #1028: add document API with atomic edits

Add the typed document facade and plugin IPC adapter. Prepare bulk edits
before mutation, preserve undo and dirty state, keep profile elevations,
validate numeric inputs and session bindings, and generate Python constructors
with typed results.

Reuse existing entity transforms and profile conversion. Compute mass
properties and closed-surface bounds in cadkernel; pin its main revision
6a5e6fc2822f6af6b2611cd605b44437b35158f0. Keep plugin API metadata at version 6.

Validation: 646 native application tests, 597 kernel tests, 12 document API
tests, 91 plugin API tests, 3 Python tests, default/IPC feature builds and
wasm32 check passed.
This commit is contained in:
Hakan Seven committed 2026-09-06 21:43:02 +03:00
commit 3385160493
50 files changed
+11481 -6

No files matched your search

+12
View File
@@ -552,6 +552,18 @@ pub trait HostApi {
let _ = tab_id;
None
}
/// DocApi v2 (`ocs_doc_api`): dispatch one bincode-serialized `DocApiEnvelope`
/// (one write op OR a read-only query batch) and return the bincode-serialized
/// `Result<Receipt, ApiError>`. Opaque bytes:
/// this crate does not depend on `ocs_doc_api`, it only routes the envelope.
///
/// Added for the DocApi v2 adapter. The default returns `Err` ("not supported");
/// the in-process host (`HostSession`) overrides it to call the DocApi executor.
fn doc_api_dispatch(&mut self, tab_id: u64, bytes: &[u8]) -> Result<Vec<u8>, String> {
let _ = (tab_id, bytes);
Err("DocApi v2 not supported by this host".to_string())
}
}
/// Simplified, read-only entity kind exposed by [`DocumentReader`].
+10
View File
@@ -138,6 +138,12 @@ pub enum PluginRequest {
GetTabId,
/// V5: ask the host for the filesystem path of the document in `tab_id`.
DocumentPath { tab_id: u64 },
/// DocApi v2 (`ocs_doc_api`): carry one bincode-serialized `DocApiEnvelope`
/// (one write op OR a read-only query batch). Appended at the end to keep
/// existing discriminants stable. The host routes this to the DocApi executor.
/// `serde_bytes` keeps the payload a single length-prefixed bulk copy (the
/// outer frame would otherwise walk it byte-by-byte).
DocApiRequest { tab_id: u64, #[serde(with = "serde_bytes")] bytes: Vec<u8> },
}
/// Responses the host sends back for `PluginRequest`.
@@ -164,6 +170,10 @@ pub enum PluginResponse {
TabId(u64),
/// V5: filesystem path of the document in the requested tab, if any.
DocumentPath(Option<std::ffi::OsString>),
/// DocApi v2 (`ocs_doc_api`): the bincode-serialized `Result<Receipt, ApiError>` answering a
/// `PluginRequest::DocApiRequest`. Appended at the end (discriminant stability).
/// `serde_bytes` keeps the payload a single length-prefixed bulk copy.
DocApiResponse { #[serde(with = "serde_bytes")] bytes: Vec<u8> },
}
/// Messages sent from the host to the plugin runner.
+4
View File
@@ -77,5 +77,9 @@ pub fn handle_plugin_request(
DocumentPath { tab_id } => PluginResponse::DocumentPath(
host.document_path(tab_id).map(|path| path.into_os_string()),
),
DocApiRequest { tab_id, bytes } => match host.doc_api_dispatch(tab_id, &bytes) {
Ok(bytes) => PluginResponse::DocApiResponse { bytes },
Err(msg) => PluginResponse::Error(msg),
},
}
}
+8 -1
View File
@@ -19,7 +19,14 @@
/// vtable so API v2 plugins keep working. v4 adds full-duplex notifications on
/// a multiplexed socket while leaving the V2/V3 ABI and protocol untouched. v5
/// adds the `BuiltinPlugin::on_load` lifecycle callback.
pub const API_VERSION: u32 = 5;
/// Host ABI major version. Bumped to 6 when the DocApi v2 surface
/// (`PluginRequest::DocApiRequest` / `PluginResponse::DocApiResponse` +
/// `HostApi::doc_api_dispatch`) was added: plugins that call DocApi require an
/// API-6 host and are rejected at handshake by older (API ≤ 5) hosts, instead of
/// failing at runtime with a bincode-decode transport error. The DocApi wire
/// changes are append-only and `doc_api_dispatch` is a defaulted method, so
/// older V2–V5 plugins still load unchanged on an API-6 host.
pub const API_VERSION: u32 = 6;
/// Oldest plugin API major the current host still loads. This keeps previously
/// compiled cdylibs usable as long as their vtable layout is a prefix of the
+1 -1
View File
@@ -147,7 +147,7 @@ mod tests {
value["ocs_plugin_api_version"].as_str(),
Some(env!("CARGO_PKG_VERSION"))
);
assert_eq!(value["api_version"].as_i64(), Some(5));
assert_eq!(value["api_version"].as_i64(), Some(crate::API_VERSION as i64));
assert_eq!(value["api_version_min_supported"].as_i64(), Some(2));
// acadrust_version should have a patch component (e.g. "0.4.0").