A Rules Engine for LLM-Assisted Work

Phronesis &
the rules
that do not fade.

A RETE rules engine that enforces project conventions from disk — outside the LLM context window. Rules fire the same in token nine hundred thousand as they do in token eight hundred. Now with trajectory predicates that watch the long run of a session, and a confidence gate that demands the build, the tests, and the known-bug catch all be green before a commit lands.

64 Rules catalogued
5 Default subsystems
8 Enforcement surfaces
4 Drift corpora
0 Rules lost to compaction
A rule is a small refusal the project keeps making, even after it has forgotten the conversation in which it was first imagined.
Eight surfaces — one rule format

Hook-time

block · warn · allow

Pre-check rules fire before edits, patches, or shell calls. Post-check rules warn after. Claude Code, Codex, and Gemini are normalized into the same fact vocabulary.

Extensible predicates

Rhai · derive · compose

Sandboxed project providers derive new LHS facts from normalized events. Multi-file tools expose a batch files view before per-file evaluation; MCP tools test and manage providers.

Audit

debt · sweep · trend

Whole-tree scan against every rule tagged audit: true. Per-rule hit counts with file and line locations. Trend snapshots track debt over time.

Durable directives

prose · re-inject

A markdown file re-injected at every SessionStart and user interaction. Project guidance fades; this does not.

Drift detection

gap · triage · suggest

One consolidated report compares CLAUDE.md, auto-memory, ADR decisions, and rule-to-code bindings against what the project currently enforces or defines. Evidence for triage, not proof.

Structural graph

query · freshness · rebuild

Rust, Python, and TypeScript structure becomes a durable graph. MCP clients can query relations, inspect generation and drift, and rebuild server-rooted graph and binding state without shell access.

Trajectory

journal · derive · cross-call

Project-defined taggers stamp executed tool calls; journey_* aggregators (occurrence, count, since-last) over bounded windows let rules match temporal patterns — auth churn over a session, recent SQL in the last five calls, build staleness — without any in-memory accumulation. Recomputed from disk every hook fire.

Grounded outcomes

compile · test · catch-the-bug

Declarative toolchain definitions feed one generic parser: Cargo ships as a built-in, while project definitions can extend or override it. Matched command outcomes become neutral signal_pass facts; gate rules block or warn a git commit by confidence band. Three grounded signals say "this is real," not three syntactic checks.

Get started — one binary, one rules file.

Install from source, run init in your project, and the hooks are wired. Rules fire from disk on every tool call — no daemon, no socket, no shared state. Every invocation is a fresh process that reads, evaluates, and exits.

Works with Claude Code, OpenAI Codex, and Gemini CLI. Exposes MCP tools to any MCP-capable client.

# install
cargo install --path crates/phronesis-mcp
phr-mcp install                # user-scope MCP

# wire into a project
cd ~/Git/my-project
phr-mcp init --packs rust             # default platform + Rust rules

# use
phr-mcp audit                    # sweep existing debt
phr-mcp trend                    # debt over time
phr-mcp drift                    # uncovered guidance across all sources
phr-mcp drift --source wiki      # narrow to ADR decisions
phr-mcp graph status --json      # inspect structural freshness
phr-mcp decision new my-slug     # scaffold an ADR page

The Explainer →

A long-form essay on the engine, the RETE algorithm, and the design intent behind moving guidance out of conversation context. With diagrams.

The Catalogue →

A visual reference of every default rule — LLM-behavior nudges, Rust enforcement, Rhai script hygiene — with rationale and worked examples from the field.

Operate Phronesis →

Use the loop-programming guide for setup, journey rules, grounded closure, graph recovery, and recurring agent workflows. Use the HTML changelog for compatibility notes and the exact release history.

The explainer contains the architecture, host integration, RETE mechanics, durable context, graph, trajectory, and confidence design in one web-native narrative. No Markdown hop is required from the documentation site.