Chapter 11: jevhooks-rules, the rule book
The routing in chapter 10 decided that an event is worth judging. Somebody now has to know two things: what exactly to ask Jev, and what to do with what it says. That somebody is this crate, and it is deliberately the dullest kind of program there is. It opens no socket, reads no file, knows no clock and waits for nothing. It is a rule book: you tell it what you know, and it tells you what should happen next.
Three things are judged, and each is a module with the same three parts:
- Facts. What can be known: "one consequential act is at least 60% likely", "there is room in memory", "this end was already refused once". A fact is a plain yes or no, or one of a few named values.
- Questions. How Jev is asked for the facts that are Jev's to give, with every term defined in the option it belongs to.
- Rules. A list of tests on facts, and what to do when they all hold. Order is priority.
flowchart LR D["the daemon<br/>(chapter 13)"] -- "here is what I know" --> N["a network of rules<br/>(rete)"] N -- "ask Jev for these facts,<br/>all in one request" --> D N -- "go and measure the room" --> D N -- "it ends: allow, ask, hold or pass" --> D W["the website<br/>(chapter 17)"] -- "draws" --> N
It is a crate of its own because of who needs it. The daemon runs the rules. The website draws them, compiled to WebAssembly, and a picture drawn from the rules that run cannot show different ones. The mod, which also runs as JavaScript inside Claude Code, needs none of it and must not carry it. One crate with no I/O serves the first two and stays out of the third.
Aside: two borrowed parts. Neither the engine nor the asking is written here. The engine is
rete, a generic rules engine that knows nothing about Jev or commands (from the sharedrustcrates, chapter 15). The asking isjev-facts(fromjevcrates, same chapter): given the facts an engine wants, it builds the one request that asks for all of them, and reads the response back into facts. What is left for this crate is the only part that is really about jevhooks: which facts, which words, which rules.
Try it.
cargo test -p jevhooks-rulesruns twenty-five tests in a few milliseconds, with no network and no key. Then readRULESinsrc/command.rs: eight rules, about thirty lines, and it is the whole policy for shell commands.
For the people who maintain it
jevhooks-rules depends on jevhooks-events (for Verdict and Tier),
rete, jev-facts, jev-protocol and serde_json, and builds for
wasm32-unknown-unknown as well as natively.
The made-up feature adds Asked::made_up to each module: answers a test
chooses, written as a real response body and read back through the same
code a real response goes through. The crate's own tests, the daemon's
tests and the website's worked examples turn it on; the daemon that ships
does not.
In this folder
| Path | What |
|---|---|
| src/ | Chapter 12: the questions, the facts and the rules. |
| Cargo.toml | The manifest, and the made-up feature. |
← Previous: Chapter 10, jevhooks-mod/src/ · Up: crates · Next: Chapter 12, jevhooks-rules/src/ →