libfse 0.1.3

Fused Semantic Execution: fail-closed policy engine with O(1)-in-rule-count scanning, zero-allocation hot path, and guaranteed enforcement semantics.
Documentation
# The Shimmy Advantage: "Glass Box" Data & Metrics


**Date:** January 25, 2026  
**Context:** `airframe` v0.1.0 Pivot to "Mean Machine" (Compliance Processing Unit)  
**Objective:** Define the proprietary data streams available only through `airframe`'s stateful, deterministic Rust architecture.

---

## 1. The Core Differentiator: "Inside the Curly Brackets"

Traditional Inference (Python/C++ wrappers):
-   **Opaque:** You send a prompt, wait, and get text. The "thinking" is hidden behind CUDA kernels and Python GIL.
-   **Estimated:** Token counts are often estimated or calculated post-hoc.
-   **Unobservable:** You cannot see the model "changing its mind" or "struggling" in real-time without massive performance penalties.

**Shimmy Reality (Stateful Rust):**
-   We own the memory, the math, and the loop.
-   We don't observe the event; we **are** the event.
-   **Zero-Copy Insight:** We can extract deep internal state at Step $N$ before proceeding to Step $N+1$ with zero overhead (reference passing).

---

## 2. The "Certified Invoice" (Compliance Data)

*Marketable Product: Audit-Grade Usage Logs*

Because we control the `InferenceControl` loop, we can generate a **Cryptographic Receipt** for every generation.

*   **The Data:**
    *   **Exact Token Count:** Not a "usage" field, but a sequential index derived from the loop counter.
    *   **Step Hash (Patent #2):** `Hash(Previous_Hash + Current_Token + Timestamp)`.
    *   **Determinism Proof:** A lightweight checksum of the KV cache state at the end of generation.
*   **The Value:**
    *   **Non-Repudiation:** "You CANNOT deny this model generated this text."
    *   **Regulatory Armor:** "Here is the exact chain of custody for every byte generated."

## 3. The "Cognitive ECG" (Quality Assurance Data)

*Marketable Product: Real-Time Hallucination/Confidence Scoring*

Most APIs give you text. Some give you logprops (probability of the chosen token). We can give you the **Cognitive Dynamics**.

*   **The Data:**
    *   **Entropy Stream:** How "flat" was the probability distribution at Step 45? (High entropy = Confusion).
    *   **Logit Gap (The "Hesitation" Index):** What was the difference between the winner and the runner-up?
        *   *Small Gap:* Model was flipping a coin (High Hallucination Risk).
        *   *Large Gap:* Model was certain.
    *   **Attention Spike (Optional):** Did the model attend strongly to the System Prompt, or overwrite it with Recency Bias?
*   **The Value:**
    *   **Predictive Filtering:** "Stop generation if Confidence drops below X% for 3 tokens."
    *   **Quality Pricing:** Charge more for "High Certainty" answers.

## 4. The "Semantic Radar" (Control & Safety Data)

*Marketable Product: Fused Semantic Execution (FSE) Telemetry*

Since FSE runs $O(1)$ checks inside the loop, we can report on **Near Misses**.

*   **The Data:**
    *   **Rule Pressure:** "The model triggered 14% of the 'Financial Advice' regex nodes, but didn't cross the threshold."
    *   **Intervention Log:** "Step 12: Blocked token 'kill' (Rule #404). Substituted 'deactivate'."
    *   **State Pilot Vector:** The exact path taken through the FSE Trie.
*   **The Value:**
    *   **Safety Tuning:** Know *exactly* how close your model is to misbehaving.
    *   **Active Defense:** Not just blocking, but reporting *intent*.

## 5. The "System Pulse" (Operational Data)

*Marketable Product: Precision SLA Monitoring*

*   **The Data:**
    *   **Micro-Latencies:** Time-to-compute for Layer 0 vs Layer 21.
    *   **Memory Modulus:** Exact quantization error accumulation (if tracking debug stats).
    *   **Energy/Compute Cost:** Exact CPU cycles per token (accessible via Rust intrinsics).
*   **The Value:**
    *   **True Cost Accounting:** "This query cost 0.0004 Joules."
    *   **Hardware Health:** Detect thermal throttling before it crashes the server.

---

## Summary: The "Shimmy Data Package"


We are not selling "Text Generation". We are selling **"Verified, Observed, & Controlled Intelligence"**.

| Feature | Standard API | Shimmy "Glass Box" |
| :--- | :--- | :--- |
| **Usage** | "705 tokens" | "Seq 1..705, Hash `sha256:...`" |
| **Quality** | "Looks good" | "Avg Entropy 0.4 bits (High Certainty)" |
| **Safety** | "Error: Content Policy" | "Blocked at Step 12 by Rule 'No-Violence'" |
| **Cost** | "$0.002" | "410ms CPU, 30MB Ram, 1.2J" |

**Next Step:** Implement the `MetricsCollector` trait alongside `TokenDecoder` to start gathering this gold.