1# Chapter 11: jevhooks-rules, the rule book 2 3The routing in chapter 10 decided that an event is worth judging. Somebody 4now has to know two things: what exactly to ask Jev, and what to do with 5what it says. That somebody is this crate, and it is deliberately the 6dullest kind of program there is. It opens no socket, reads no file, knows 7no clock and waits for nothing. It is a rule book: you tell it what you 8know, and it tells you what should happen next. 9 10Three things are judged, and each is a module with the same three parts: 11 12- **Facts.** What can be known: "one consequential act is at least 60% 13 likely", "there is room in memory", "this end was already refused once". 14 A fact is a plain yes or no, or one of a few named values. 15- **Questions.** How Jev is asked for the facts that are Jev's to give, 16 with every term defined in the option it belongs to. 17- **Rules.** A list of tests on facts, and what to do when they all hold. 18 Order is priority. 19 20```mermaid 21flowchart LR 22 D["the daemon<br/>(chapter 13)"] -- "here is what I know" --> N["a network of rules<br/>(rete)"] 23 N -- "ask Jev for these facts,<br/>all in one request" --> D 24 N -- "go and measure the room" --> D 25 N -- "it ends: allow, ask, hold or pass" --> D 26 W["the website<br/>(chapter 17)"] -- "draws" --> N 27``` 28 29It is a crate of its own because of who needs it. The daemon runs the 30rules. The website draws them, compiled to WebAssembly, and a picture drawn 31from the rules that run cannot show different ones. The mod, which also 32runs as JavaScript inside Claude Code, needs none of it and must not carry 33it. One crate with no I/O serves the first two and stays out of the third. 34 35> **Aside: two borrowed parts.** Neither the engine nor the asking is 36> written here. The engine is `rete`, a generic rules engine that knows 37> nothing about Jev or commands (from the shared `rustcrates`, chapter 38> 15). The asking is `jev-facts` (from `jevcrates`, same chapter): given 39> the facts an engine wants, it builds the one request that asks for all 40> of them, and reads the response back into facts. What is left for this 41> crate is the only part that is really about jevhooks: which facts, 42> which words, which rules. 43 44> **Try it.** `cargo test -p jevhooks-rules` runs twenty-five tests in a 45> few milliseconds, with no network and no key. Then read 46> `RULES` in `src/command.rs`: eight rules, about thirty lines, and it is 47> the whole policy for shell commands. 48 49## For the people who maintain it 50 51`jevhooks-rules` depends on `jevhooks-events` (for `Verdict` and `Tier`), 52`rete`, `jev-facts`, `jev-protocol` and `serde_json`, and builds for 53`wasm32-unknown-unknown` as well as natively. 54 55The `made-up` feature adds `Asked::made_up` to each module: answers a test 56chooses, written as a real response body and read back through the same 57code a real response goes through. The crate's own tests, the daemon's 58tests and the website's worked examples turn it on; the daemon that ships 59does not. 60 61### In this folder 62 63| Path | What | 64| --- | --- | 65| [src/](src/) | Chapter 12: the questions, the facts and the rules. | 66| [Cargo.toml](Cargo.toml) | The manifest, and the `made-up` feature. | 67 68← Previous: [Chapter 10, jevhooks-mod/src/](../jevhooks-mod/src/) · Up: [crates](../) · Next: [Chapter 12, jevhooks-rules/src/](src/) →