rationale-engine
by skupriienko
README.md
# rationale-engine
[](https://www.python.org/downloads/)
[](rust/Cargo.toml)
[](LICENSE)
[-10b981.svg)](#installation)
[](#mcp-server-setup)
**Stop merging unexplained diffs, sycophantic AI plans, and wishful strategy memos. Verify 5-layer first-principles rationale, pre-mortem failure modes, and falsifiable kill criteria in `< 80 µs` with zero dependencies.**
Architecture docs rot into changelog lists (`"Switched to Redis"`), while RLHF models flatter weak proposals and bury irreversible bets. **`rationale-engine` (`v2.0.0`)** pairs a zero-dependency **Pure Safe Rust (`#![forbid(unsafe_code)]`) UTF-8 scanner** with a **block-aware multi-decision parser**, **6 domain profiles** (`generic`, `software-engineering`, `ai-ml-systems`, `product-business`, `security-governance`, `scientific-research`), **42 epistemic rules** (including anti-sycophancy & ML baseline gates), **MCDA +/-15% sensitivity**, **7 export formats**, an **8-audience rigor advisor**, and a **12-tool Stdio MCP server** — with **0 runtime dependencies**.
**[Try Live in Browser](https://skupriienko.github.io/#tab-rationale)** · **[AI & Benchmark Guide](docs/AI_AGENTIC_USAGE_AND_BENCHMARK.md)** · **[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 proposals through `run_rationale_chain()` or `rationale-engine chain`:
```text
RAW PROPOSAL (Score: 20.0/100 · FAIL — missing layers 2..5, changelog-only):
## Decision 1: Cache Layer
Switched to Redis because it is obviously best practice. TODO: add details later.
```
```text
VERIFIED 5-LAYER RATIONALE (Score: 100.0/100 · PASS · SHA-256 receipt minted):
1. CS / OS / Protocol Fundamentals -> Bounded RAM cache vs durable disk I/O
2. Threat Model / Failure Mode -> Thundering herd + eviction storm (CWE-400)
3. Trade-off & Reversibility Door -> In-process LRU vs Redis (Two-Way Door, N.x safe)
4. Runtime & Stdlib Implementation -> `functools.lru_cache` + `threading.RLock`
5. Edge Cases & Kill Criteria -> Cold-start cap; rollback if p99 > 40 ms
```
---
## Two Core Tracks: Generic & Software Engineering
| Layer | Generic Decisions (`profile="generic"`) | Software Engineering (`profile="software-engineering"`) |
| :---: | :--- | :--- |
| **1** | **First-Principles Laws & Domain Axioms** | **CS / OS / Protocol Fundamentals** |
| **2** | **Pre-Mortem Failure Modes, Risks & Asymmetry** | **Threat Model / Failure Mode (`CWE-*`, `TOCTOU`)** |
| **3** | **Alternatives Matrix, *Via Negativa* & Door Type** | **Engineering Trade-off, *Via Negativa* & `SemVer`** |
| **4** | **Operational Mechanism & Named Owners** | **Language Runtime, Stdlib & SDK Symbols** |
| **5** | **Stress Edge Cases & Falsifiable Kill Criteria** | **Production Topologies, Edge Cases & TDD/Kill Gates** |
Additional built-in profiles: `product-business`, `ai-ml-systems`, `security-governance`, `scientific-research`, plus `register_domain_profile()`.
---
## Architecture (`v1.0.0`)
```mermaid
flowchart TD
IN["Proposal Markdown + Profile"] --> WIRE{"Machine Wire Format?"}
WIRE -->|"Yes (JSON-RPC / Protobuf / SQL)"| SKIP["Bypass Engine (LAW_07)"]
WIRE -->|"No (Human Proposal)"| PARSE["Block-AST Parser (Per-Decision + Fence Isolation)"]
PARSE --> RUST["Pure Safe Rust Scanner (O(N) UTF-8)"]
RUST --> RULES["36 Epistemic Rules + One-Way Door Gate"]
RULES --> FSM["7-Law Rationale FSM + SVG Scorecard + SHA-256 Receipt"]
```
---
## Installation
Install directly from GitHub in one command (`Python 3.10+`, `dependencies = []`):
```bash
pip install "git+https://github.com/skupriienko/rationale-engine.git"
```
For local development with the optional zero-crate Pure Safe Rust (`#![forbid(unsafe_code)]`) accelerator:
```bash
git clone https://github.com/skupriienko/rationale-engine.git
cd rationale-engine
cargo build --release --manifest-path rust/Cargo.toml
pip install -e ".[dev]"
```
---
## 30-Second Python Quickstart
```python
from rationale_engine import (
evaluate_tradeoff_matrix,
export_rationale,
render_rationale_template,
run_rationale_chain,
verify_rationale,
)
# 1. Generate a Generic or Software Engineering blueprint
blueprint = render_rationale_template(
title="Regional Hub Consolidation",
profile="generic",
door_type="one_way",
)
# 2. Verify a multi-decision proposal (ignores prose mentions & code-block TODOs)
result = run_rationale_chain(blueprint, profile="generic")
print("Score:", result["report"]["score"], "Passed:", result["passed"])
# 3. Detect fragile trade-offs with +/-15% MCDA weight perturbation
mcda = evaluate_tradeoff_matrix(
options=[
{"name": "Option A", "scores": {"safety": 9.0, "speed": 5.0}, "complexity": 2.0},
{"name": "Option B", "scores": {"safety": 5.2, "speed": 9.0}, "complexity": 4.0},
],
weights={"safety": 0.51, "speed": 0.49},
)
print("Winner:", mcda["winner"], "Fragile flip:", mcda["fragile_flip_detected"])
# 4. Export to MADR 4.0, GitHub PR, or Executive Memo
madr = export_rationale("Adopt SQLite WAL", profile="software-engineering", fmt="madr")
```
---
## MCP Server Setup
Add `rationale-engine` to Claude Code, Cursor, Windsurf, or any JSON-RPC 2.0 MCP client:
```json
{
"mcpServers": {
"rationale-engine": {
"command": "rationale-engine",
"args": ["mcp"]
}
}
}
```
| MCP Tool | Purpose |
| :--- | :--- |
| `rationale_template` | Generate 5-layer Generic or SE blueprint |
| `rationale_verify` | Audit multi-decision Markdown + Rust metrics |
| `rationale_chain` | 6-stage pipeline + SVG + SHA-256 receipt |
| `rationale_fsm` | 7-Law Epistemic FSM evaluation |
| `rationale_mcda` | Weighted MCDA + +/-15% sensitivity check |
| `rationale_export` | Render 5-layer, MADR, GitHub PR, or Memo |
| Utility Tool | Purpose |
| :--- | :--- |
| `rationale_advise` | Recommend rigor tier (`bypass`..`strict_one_way_gate`) for 8 audiences & AI stages |
| `rationale_rules` | List all 42 epistemic rules across 7 families |
| `rationale_svg` | Render light-atelier SVG scorecard |
| `rationale_profiles` | List 6 built-in + custom domain profiles |
| `rationale_register_profile` | Register a custom 5-layer profile at runtime |
| `rationale_benchmark` | Benchmark Pure Safe Rust vs Python scanner |
---
## CLI & Verification
```bash
rationale-engine template --profile generic --title "Pricing Tier Migration"
rationale-engine verify --file proposal.md --profile software-engineering --json
rationale-engine chain --file proposal.md --profile auto --json
rationale-engine export --title "Adopt SQLite WAL" --profile software-engineering --format madr
```
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/rationale_engine && pytest -W error
```
---
## Scope & When NOT to Use
- **Best Fit:** Architecture Decision Records (ADRs), RFCs, migrations, security hardening, executive strategy memos, product bets, and research protocols.
- **Do NOT Use On:** Machine wire formats (`JSON-RPC`, `Protobuf`, `SQL DDL`), trivial typo fixes, or routine formatting commits.
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.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues