Skip to main content
Glama
eloquence-engine

eloquence-engine

by skupriienko
README.md
# eloquence-engine

[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![Rust: 2021 cdylib](https://img.shields.io/badge/rust-cdylib%20%2B%20std-orange.svg)](rust/Cargo.toml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Dependencies: Zero](https://img.shields.io/badge/dependencies-0%20(pure%20stdlib)-10b981.svg)](#installation)
[![MCP: 10 Stdio Tools](https://img.shields.io/badge/MCP-10%20Stdio%20Tools-6366f1.svg)](#mcp-server-setup)

**Stop shipping robotic AI prose. Lint, polish, and structure human-facing text in `< 90 µs` with zero dependencies.**

LLMs pad replies with throat-clearing filler, flatten sentence rhythm into a monotone drone, and bury decisions under generic hedging. **`eloquence-engine` (`v2.1.0`)** pairs a zero-dependency **Rust C-ABI UTF-8 scanner** with a **Python 7-axis control plane** and a **10-tool Stdio MCP server**. It strips AI filler deterministically, gates technical specs with **context-aware ASD-STE100**, and verifies **7 rhetorical state-machine laws** across **16 surfaces** and **10+ languages** (Latin, Cyrillic, Arabic, and unspaced CJK) — with **0 runtime dependencies**, **0 GPU**, and **0 external API keys**.

**[Try Live in Browser](https://skupriienko.github.io/#tab-eloquence)** · **[10-Second Install](#installation)** · **[MCP Server Setup](#mcp-server-setup)** · **[Architecture](docs/ARCHITECTURE_AND_RATIONALE.md)** · **[Formal Specification](docs/SPECIFICATION_AND_LIMITATIONS.md)**

---

## Before & After in One Deterministic Pass

Pass raw LLM output through `run_eloquence_chain()` or `eloquence-engine chain`:

```text
RAW DRAFT (Score: 54.0/100 · FAIL — ai_slop_detected, bureaucratic_jargon):
Certainly! Let's dive in. In today's fast-paced world, we must utilize an outbox
in order to eliminate dropped webhooks. Latency dropped from 420 ms to 19 ms.
I hope this helps!
```

```text
POLISHED & VERIFIED (Score: 100.0/100 · PASS · SHA-256 receipt minted):
We must use an outbox to eliminate dropped webhooks. Latency dropped from 420 ms to 19 ms.
```

---

## Architecture (`v2.1.0`)

```mermaid
flowchart TD
    IN["Raw Draft + 7-Axis Context"] --> WIRE{"Human-Read Output?"}
    WIRE -->|"No (JSON-RPC / Protobuf / SQL / Binary)"| SKIP["Bypass Engine (Preserve Wire Format)"]
    WIRE -->|"Yes (Humans Only)"| PLAN["compose_human_blueprint() + ste100_policy"]
    PLAN --> POL["polish_prose(replace_jargon=True)"]
    POL --> STE{"English Technical Spec?"}
    STE -->|"Yes (docs_runbook / rfc_adr_memo)"| CHECK["audit_ste100() Issue 9 Gate"]
    STE -->|"No (Speech / Narrative / Non-EN)"| RUST["Rust C-ABI Scalar Scanner (O(N) UTF-8 + CJK)"]
    CHECK --> RUST
    RUST --> FSM["audit_rhetorical_fsm() + Scorecard SVG + SHA-256 Receipt"]
```

```mermaid
flowchart LR
    CORE["Rust C-ABI Kernel (eloquence_rs)"] --> BRIDGE["ctypes Bridge + 1:1 Python Fallback"]
    LOC["10+ LocalePacks (en, uk, es, fr, de, pt, it, ja, zh, ar + Custom)"] --> BRIDGE
    BRIDGE --> API["Python SDK (plan, audit, polish, ste100, fsm, chain, svg)"]
    API --> CLI["CLI (eloquence-engine)"]
    API --> MCP["10-Tool Stdio JSON-RPC 2.0 MCP Server"]
```

---

## Installation

Install directly from GitHub in one command (`Python 3.10+`, `dependencies = []`):

```bash
pip install "git+https://github.com/skupriienko/eloquence-engine.git"
```

For local development with the optional zero-crate Rust `cdylib` accelerator:

```bash
git clone https://github.com/skupriienko/eloquence-engine.git
cd eloquence-engine
cargo build --release --manifest-path rust/Cargo.toml
pip install -e ".[dev]"
```

---

## 30-Second Python Quickstart

```python
from eloquence_engine import (
    audit_ste100,
    compose_human_blueprint,
    polish_prose,
    register_locale_pack,
    render_scorecard_svg,
    run_eloquence_chain,
)

# 1. Resolve 7-axis blueprint + context-gated ASD-STE100 policy
blueprint = compose_human_blueprint(
    audience="executive_board",
    intent="persuade_decide",
    usage_domain="engineering_it",
    target_surface="rfc_adr_memo",
    language="en",
)
print("STE-100 policy:", blueprint["ste100_policy"]["tier"])

# 2. Run full 6-stage chain (wire gate -> blueprint -> polish -> STE100 -> Rust audit -> FSM + SVG)
draft = (
    "Certainly! We must utilize an idempotency key in order to stop duplicate webhooks. "
    "Because PostgreSQL rejects duplicates at commit time, retries stay safe. "
    "Latency fell from 420 ms to 19 ms. Next step: deploy Thursday at 10:00 UTC. I hope this helps!"
)
result = run_eloquence_chain(draft, target_surface="rfc_adr_memo", intent="persuade_decide")
print("Score:", result["audit"]["score"], "Passed:", result["passed"], "Receipt:", result["receipt_sha256"][:12])

# 3. Context-gated STE-100 skips non-English and oratorical prose automatically
skipped = audit_ste100(
    "We don't utilize short lines on stage.",
    mode="auto",
    target_surface="speech",
    usage_domain="public_media",
    intent="inspire_storytell",
    enforce_context_gate=True,
)
assert skipped["skipped"] is True

# 4. Polish standalone drafts or register custom language packs
clean = polish_prose(draft, replace_jargon=True)
svg = render_scorecard_svg(result["audit"])
register_locale_pack("nl", name="Dutch", ai_slop_phrases=("het is belangrijk om op te merken",))
```

---

## Context-Gated `ASD-STE100` Policy

Strict controlled English helps incident runbooks, yet flattens speeches and breaks non-English prose. `resolve_ste100_policy()` activates STE-100 rules only where precision beats rhetorical flair:

| Context (`surface`, `domain`, `intent`, `language`) | State | Word Limit & Behavior |
| :--- | :--- | :--- |
| `docs_runbook` or `engineering_it` + `instruct_guide` (`en`) | **Strict Procedural** | `<= 20` words/sentence, active voice, 1 instruction/bullet |
| `rfc_adr_memo`, `github_readme`, `research`, `ai_chat_response` (`en`) | **STE-Flavored Descriptive** | `<= 25` words/sentence, active voice, `<= 3`-noun clusters |
| `speech`, `presentation`, `book`, `article`, `personal_note`, non-EN | **Disabled (`skipped=True`)** | Preserves cadence burstiness, imagery, and native syntax |

---

## MCP Server Setup

Add `eloquence-engine` to Claude Code, Cursor, Windsurf, or any JSON-RPC 2.0 MCP client:

```json
{
  "mcpServers": {
    "eloquence-engine": {
      "command": "eloquence-engine",
      "args": ["mcp"]
    }
  }
}
```

| MCP Tool | Purpose |
| :--- | :--- |
| `eloquence_plan` | 7-axis blueprint + `ste100_policy` |
| `eloquence_audit` | Rust C-ABI cadence & slop audit |
| `eloquence_polish` | Strip AI filler outside code fences |
| `eloquence_ste100` | Context-gated ASD-STE100 check |
| `eloquence_fsm` | 7-Law Rhetorical FSM check |

| Utility Tool | Purpose |
| :--- | :--- |
| `eloquence_chain` | 6-stage pipeline + SHA-256 receipt |
| `eloquence_svg` | Render light-atelier SVG scorecard |
| `eloquence_locales` | List 10+ built-in and custom locales |
| `eloquence_catalog` | Return 7-axis taxonomy catalog |
| `eloquence_benchmark` | Compare Rust C-ABI vs Python speed |

---

## CLI & Verification

```bash
eloquence-engine plan --audience executive_board --intent persuade_decide --target executive_brief
eloquence-engine audit --file README.md --target github_readme --json
eloquence-engine polish --file draft.md --replace-jargon
eloquence-engine ste100 --file runbook.md --target docs_runbook --enforce-context-gate --json
eloquence-engine fsm --file memo.md --target rfc_adr_memo --json
eloquence-engine chain --file memo.md --target rfc_adr_memo --json
eloquence-engine svg --file memo.md > scorecard.svg
```

Run the full Rust + Python verification suite locally:

```bash
cargo test --manifest-path rust/Cargo.toml --release
ruff check src tests examples && mypy --strict src/eloquence_engine && pytest -W error
```

---

## Scope & When NOT to Use

- **Best Fit:** Technical READMEs, RFCs/ADRs, operational runbooks, executive briefs, emails, research reports, speeches, and web essays.
- **Do NOT Use On:** Machine wire protocols (`JSON-RPC`, `Protobuf`, `SQL DDL`, binary frames, cryptographic hashes) or poetic meter.

See [docs/ARCHITECTURE_AND_RATIONALE.md](docs/ARCHITECTURE_AND_RATIONALE.md) and [docs/SPECIFICATION_AND_LIMITATIONS.md](docs/SPECIFICATION_AND_LIMITATIONS.md) for formal specifications.