Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: CI
on: [push, pull_request]

jobs:
test:
name: Test & lint (${{ matrix.rust }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust: [stable, beta]
steps:
Expand All @@ -12,6 +15,23 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy
- run: cargo fmt --all -- --check
- run: cargo test --verbose
- run: cargo clippy -- -D warnings
- name: Format check
run: cargo fmt --all -- --check
- name: Clippy (all targets, all features)
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Test (default features)
run: cargo test --verbose
- name: Test (all features)
run: cargo test --all-features --verbose

wasm:
name: wasm32 build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: wasm32-unknown-unknown
- name: Build for wasm32-unknown-unknown
run: cargo build --target wasm32-unknown-unknown --verbose
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description = "FLUX bytecode conservation-law enforcement for LLM outputs (Rust)
repository = "https://github.com/SuperInstance/conservation-enforcer-rs"
homepage = "https://github.com/SuperInstance/conservation-enforcer-rs"
keywords = ["flux", "conservation", "llm", "policy", "bytecode"]
categories = ["no-std", "embedded", "wasm"]
categories = ["wasm"]

[lib]
name = "conservation_enforcer"
Expand Down
45 changes: 35 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

![Crates.io](https://img.shields.io/crates/v/si-conservation-enforcer)
![Rust](https://img.shields.io/badge/rust-stable-orange)
![Tests](https://img.shields.io/badge/tests-95%2B-brightgreen)
![no_std](https://img.shields.io/badge/no__std-compatible-blue)
![Tests](https://img.shields.io/badge/tests-150%2B-brightgreen)
![License](https://img.shields.io/github/license/SuperInstance/conservation-enforcer-rs)

**FLUX bytecode conservation-law enforcement for LLM outputs.**
Expand All @@ -27,13 +26,18 @@ User Request → LLM Call → [FLUX Conservation Validator] → Response

## Why Rust?

| Property | Benefit |
|----------|---------|
| **Zero-cost abstractions** | The entire VM, assembler, and enforcement layer adds negligible overhead |
| **`no_std` compatible** | Works in embedded, WASM, and kernel contexts (`default-features = false`) |
| **Zero external dependencies** | The entire crate is self-contained — no transitive dependency risk |
| **Memory safe** | Rust's ownership model guarantees no UB in the policy VM |
| **Deterministic** | Same input + bytecode = same output, every time |
- **Zero-cost abstractions** — The entire VM, assembler, and enforcement layer adds negligible overhead
- **WASM-ready** — Builds unmodified for `wasm32-unknown-unknown` with the default `std` feature
- **No external dependencies** — The entire crate is self-contained
- **Memory safe** — Rust's ownership model guarantees no UB in the policy VM
- **Deterministic** — Same input + bytecode = same output, every time

> **`no_std` status:** The crate is annotated with `#![cfg_attr(not(feature = "std"), no_std)]`
> and has scaffolding for a `no_std`/embedded port, but building with
> `--no-default-features` does **not** currently compile (the implementation uses
> `String`/`Vec`/`format!` and `std::collections::HashMap`). Treat `no_std`/embedded
> support as a stated goal, not a working configuration. The `wasm32-unknown-unknown`
> target (with `std`) is supported.

## Installation

Expand Down Expand Up @@ -289,6 +293,16 @@ The assembler supports higher-level pseudo-instructions that expand to multiple
| `audit` | ❌ | JSON Lines audit logging to files |
| `metrics` | ❌ | Metrics collection and export |

> **Note:** A `no_std`/embedded build (`default-features = false`) is a stated
> goal but does **not** currently compile (see `no_std` status above). The
> snippet below is the intended usage once that port lands; it is not functional today.
>
> ```toml
> [dependencies]
> # Not yet working — requires the unfinished no_std port.
> si-conservation-enforcer = { version = "0.1", default-features = false }
> ```

### Audit Logging

```rust
Expand Down Expand Up @@ -317,6 +331,14 @@ let snapshot = metrics.snapshot();
println!("Block rate: {:.1}%", snapshot.block_rate * 100.0);
```

This crate is a Rust implementation of the same FLUX ISA and policy
semantics as the [Python conservation-enforcer](https://github.com/SuperInstance/conservation-enforcer).
It is **not** a verified line-by-line port: the two implementations are maintained
independently, this Rust suite is its own test suite (not a replication of the
Python suite), and cross-implementation bytecode compatibility is a design goal
that is **not** currently verified by CI or tests. Treat the table below as a
component mapping, not a parity guarantee.

## Architecture

```
Expand All @@ -337,6 +359,9 @@ src/
├── policies (7 pre-built conservation policies)
├── audit (JSONL audit log, feature-gated)
└── metrics (MetricsCollector, feature-gated)

tests/
└── integration.rs Integration test suite (~80 tests; 150+ tests total with unit + doc tests)
```

### No External Dependencies
Expand All @@ -346,7 +371,7 @@ The entire crate — VM, assembler, enforcer, policies, audit, metrics — has *
## Testing

```bash
# Run all 95+ tests
# Run all 150+ tests
cargo test

# Run with output
Expand Down
Loading
Loading