Skip to content

Commit ea5b39f

Browse files
teryltTeryl Tayloraraujof
authored andcommitted
feat: RUST with CMF and extensions. (contextforge-org#44)
* 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>
1 parent e518adb commit ea5b39f

38 files changed

Lines changed: 5826 additions & 167 deletions

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ authors = ["Teryl Taylor"]
2020

2121
[workspace.dependencies]
2222
tokio = { version = "1", features = ["full"] }
23-
serde = { version = "1", features = ["derive"] }
23+
serde = { version = "1", features = ["derive", "rc"] }
2424
serde_yaml = "0.9"
2525
serde_json = "1"
2626
async-trait = "0.1"

crates/cpex-core/examples/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,40 @@ The demo runs five scenarios against three registered plugins:
4141

4242
- `plugin_demo.rs` — Rust source with plugins, factories, and main
4343
- `plugin_demo.yaml` — YAML config with plugins, policy groups, and routes
44+
45+
---
46+
47+
## cmf_capabilities_demo
48+
49+
Demonstrates CMF messages with capability-gated extension access. Shows how different plugins see different views of the same extensions based on their declared capabilities.
50+
51+
### What it demonstrates
52+
53+
- **CMF Message** — typed content parts (`Text`, `ToolCall`) with the standard CMF format
54+
- **Capability gating** — plugins declare capabilities in YAML config; the executor filters extensions per plugin
55+
- **Security labels**`MonotonicSet` (add-only, no remove at compile time)
56+
- **Guarded HTTP headers**`.read()` is free, `.write(token)` requires a `WriteToken`
57+
- **COW copy**`extensions.cow_copy()` for plugins that need to modify; zero-cost for read-only plugins
58+
- **Write tokens** — executor sets tokens based on capabilities; propagated through `cow_copy()`
59+
- **Three capability levels** — identity-checker (security), header-injector (http + labels), audit-logger (http + labels read-only)
60+
61+
### Running
62+
63+
From the workspace root:
64+
65+
```
66+
cargo run --example cmf_capabilities_demo
67+
```
68+
69+
### What each plugin sees
70+
71+
| Plugin | Capabilities | Security Labels | Subject | HTTP Headers | Can Write |
72+
|--------|-------------|-----------------|---------|--------------|-----------|
73+
| identity-checker | read_labels, read_subject, read_roles | visible | visible (id + roles) | hidden | no |
74+
| header-injector | read_headers, write_headers, append_labels | visible | hidden | visible | yes (headers + labels) |
75+
| audit-logger | read_headers, read_labels | visible | hidden | visible | no (audit mode) |
76+
77+
### Files
78+
79+
- `cmf_capabilities_demo.rs` — Rust source with CMF plugins and capability-gated access
80+
- `cmf_capabilities_demo.yaml` — YAML config with per-plugin capabilities

0 commit comments

Comments
 (0)