Skip to content

feat: RUST with CMF and extensions.#44

Merged
araujof merged 9 commits into
devfrom
feat/cmf_rust
May 4, 2026
Merged

feat: RUST with CMF and extensions.#44
araujof merged 9 commits into
devfrom
feat/cmf_rust

Conversation

@terylt
Copy link
Copy Markdown
Contributor

@terylt terylt commented Apr 29, 2026

Summary

Adds CMF (ContextForge Message Format) types, full extension model with 11 typed extensions, capability-gated
filtering, mutability tier enforcement (MonotonicSet, Guarded, WriteToken), and COW-based extension modification to
the CPEX Rust core.

Closes: #17

Changes

  • cmf/ module — CMF Message, ContentPart (tagged enum), domain objects (ToolCall, ToolResult, Resource, etc.),
    enums, MessageView with OPA serialization
  • extensions/ module — all 11 extension types matching Python: Security (with AgentIdentity), Http, Delegation,
    Agent, Request, Completion, Provenance, LLM, MCP, Framework, Meta
  • extensions/monotonic.rsMonotonicSet<T> add-only set, no remove() at compile time
  • extensions/guarded.rsGuarded<T> + WriteToken for capability-gated write access
  • extensions/filter.rsfilter_extensions() with granular security sub-field filtering, slot registry with
    policies
  • hooks/payload.rsExtensions expanded to 11 slots with Arc immutable + owned mutable/monotonic, cow_copy()
    for zero-cost COW, validate_immutable() for tamper detection, write token propagation
  • executor.rsfilter_extensions() wired into all 4 phases, write tokens set from capabilities, tier validation
    (immutable + monotonic) on modified extensions
  • FilteredExtensions removed — single Extensions type, handlers receive &Extensions (immutable, zero-copy)
  • cmf_capabilities_demo example — CMF message + config-driven capability gating end-to-end
  • SDK re-exports for CMF types
  • serde rc feature enabled for Arc serialization

Architecture highlights

  • Zero-copy for read-only plugins — handler receives &Extensions, no clone. 95% of plugins pay nothing.
  • COW for modifying pluginsextensions.cow_copy() clones only mutable slots (Arc bumps for 8 of 12 immutable
    slots). Write tokens propagate from the executor, can't be forged (pub(crate) constructor).
  • Compile-time tier enforcementMonotonicSet has no remove(), Guarded requires WriteToken for
    .write(). Plugin crates can't construct tokens.
  • Executor validationvalidate_immutable() uses Arc::ptr_eq to detect immutable slot tampering. Monotonic
    superset check ensures labels only grow.
  • Concurrent/fire-and-forgetArc<Extensions> shared across spawned tasks, one clone into the Arc, then
    refcount bumps per task.

Test plan

  • 175 tests pass (76 original + 99 new)
  • Zero compiler warnings
  • cargo run --example plugin_demo works
  • cargo run --example cmf_capabilities_demo works
  • CMF serde round-trips match Python format
  • Capability filtering: plugins without capabilities see None/empty
  • COW: modifications on copy, original unchanged, immutable Arcs shared
  • Write tokens: propagated through cow_copy, not clonable, not forgeable
  • Executor rejects immutable slot tampering
  • Executor rejects monotonic label removal
  • Executor accepts valid label additions via cow_copy
  • Sensitive headers (Authorization, Cookie, X-API-Key) stripped in OPA serialization

New test coverage

Module Tests Covers
cmf/enums 7 Serde round-trips for all enums
cmf/content 10 All content part types, domain objects, Resource helpers
cmf/message 11 Message helpers, serde, MessagePayload as PluginPayload
cmf/view 17 Views, actions, hooks, extensions, to_dict, to_opa_input, sensitive header stripping
extensions/security 10 AgentIdentity, SubjectExtension, labels, serde, ObjectSecurityProfile, DataPolicy
extensions/http 8 Case-insensitive get/set/has, add-if-absent, remove, serde
extensions/delegation 4 Append hop, multiple hops, scope narrowing, serde
extensions/monotonic 5 Add-only, superset, declassifier, case-insensitive labels, serde
extensions/guarded 4 Read without token, write with token, serde transparent
extensions/filter 8 Per-capability visibility, granular security sub-fields
extensions/tiers 2 Tier and capability serde
hooks/payload (COW) 11 cow_copy Arc sharing, token propagation, validate_immutable, multi-field modify,
read-only zero-cost
manager (tier validation) 3 Executor accepts valid labels, rejects immutable tampering, capability filtering
integration

Teryl Taylor added 8 commits April 14, 2026 17:01
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
@araujof araujof changed the title Feat: RUST with CMF and extensions. feat: RUST with CMF and extensions. May 1, 2026
@araujof araujof added enhancement New feature or request Rust labels May 1, 2026
@araujof araujof added this to CPEX May 1, 2026
@araujof araujof added this to the 0.2.0 milestone May 1, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in CPEX May 1, 2026
@araujof araujof moved this from Backlog to In progress in CPEX May 1, 2026
@terylt terylt marked this pull request as ready for review May 1, 2026 16:49
@terylt terylt requested review from araujof and jonpspri as code owners May 1, 2026 16:49
@araujof araujof changed the base branch from main to dev May 4, 2026 18:44
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Copy link
Copy Markdown
Contributor

@araujof araujof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Merging into dev and review this changeset with #45 (branched from this PR).

@araujof araujof merged commit 81ba56b into dev May 4, 2026
@araujof araujof deleted the feat/cmf_rust branch May 4, 2026 18:58
@github-project-automation github-project-automation Bot moved this from In progress to Done in CPEX May 4, 2026
@araujof araujof self-assigned this May 4, 2026
araujof added a commit that referenced this pull request May 7, 2026
* feat: initial revision rust core.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: addressed comments in PR. Updated PluginContext to match spec.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: RUST CMF initial revision.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added invoke named support, added constants, fixed reviewed code.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added owned extensions and did some refactoring.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com>
monshri pushed a commit to monshri/contextforge-plugins-framework that referenced this pull request May 27, 2026
* feat: initial revision rust core.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: addressed comments in PR. Updated PluginContext to match spec.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: RUST CMF initial revision.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added invoke named support, added constants, fixed reviewed code.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added owned extensions and did some refactoring.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request framework Rust

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEATURE]: CMF extension types in Rust

2 participants