jevhooks.git / crates / README.md
1# Chapter 6: crates, four Rust packages and why there are four
2
3Everything the plugin does that is not plumbing is Rust, in four crates (a
4crate is Rust's package: one `Cargo.toml`, the way an npm package has one
5`package.json`). Each exists because of where it has to run.
6
7- **jevhooks-events** runs everywhere. It is the vocabulary: the hook
8  events, what is done with each, the verdict and the decision. It does no
9  I/O at all, so it compiles both into the mod and into the daemon.
10- **jevhooks-mod** runs inside Claude Code. It is compiled to WebAssembly
11  and then to JavaScript, and decides in well under a millisecond what to
12  do with each event.
13- **jevhooks-rules** runs wherever it is asked to, and does nothing by
14  itself. It is the rule book: what Jev is asked, and the rules that turn
15  its answers into what happens. The daemon runs it; the website draws it.
16- **jevhooks-daemon** runs as its own process. It is the `jevhooks` binary:
17  the daemon that asks Jev, the per-session MCP server, and the
18  command-line tools that read them.
19
20```mermaid
21flowchart BT
22  events["jevhooks-events<br/>the vocabulary, no I/O"]
23  modc["jevhooks-mod<br/>routing, as JavaScript"]
24  rules["jevhooks-rules<br/>questions and rules, no I/O"]
25  daemon["jevhooks-daemon<br/>the jevhooks binary"]
26  jevcrates["jev-http, jev-facts, jev-protocol<br/>(third-party/jevcrates)"]
27  rete["rete<br/>(third-party/rustcrates)"]
28  rmcp["rmcp<br/>(crates.io, 3.5.1 or later)"]
29  modc --> events
30  rules --> events
31  rules --> rete
32  rules --> jevcrates
33  daemon --> events
34  daemon --> rules
35  daemon --> jevcrates
36  daemon --> rmcp
37```
38
39(An arrow means "depends on".)
40
41The point of the split is the line down the middle. The mod and the daemon
42live in different processes and speak JSON over a socket; the only way to
43be sure they agree on what `"PreToolUse"` or `"ask"` means is for both to be
44compiled from the same Rust enum. That enum is in `jevhooks-events`, and
45it is the only thing the two sides share.
46
47> **Aside: the version that matters.** The root `Cargo.toml` asks for
48> rmcp, the Rust MCP library, at 3.5.1 or later, and the "or later" is not
49> decoration. rmcp 3.5.0 refuses every request after the way Claude Code
50> opens a stdio server (`server/discover`, then `initialize`), so on 3.5.0
51> the MCP server connects and offers no tools, with no error anywhere a
52> person would look. For a few days this repository carried its own fix on
53> a fork; rmcp 3.5.1 fixed it upstream, and the fork is gone.
54
55> **Try it.** `mise run test` (or `cargo test`) from the repository
56> root runs every crate's tests. None of them needs the network, a Jev
57> key or a daemon: the verdicts are tested on made-up probabilities, and
58> the routing on made-up events.
59
60The chapters that follow take them in the order an event meets them: the
61vocabulary (7 and 8), the routing in the mod (9 and 10), the rule book (11
62and 12), the daemon (13 and 14).
63
64## For the people who maintain it
65
66All four are version `0.1.0`, edition 2024, `publish = false`, and take
67every dependency's version from the root `Cargo.toml`'s
68`[workspace.dependencies]`. The release profile there (`opt-level = "s"`,
69`lto`, `panic = "abort"`, one codegen unit) applies to the wasm build and
70to the daemon alike.
71
72### In this folder
73
74| Crate | What |
75| --- | --- |
76| [jevhooks-events/](jevhooks-events/) | Chapters 7 and 8: every hook event, its role, the verdict and the decision. Depends on `serde` only. |
77| [jevhooks-mod/](jevhooks-mod/) | Chapters 9 and 10: the routing and the read-only filter, built as a `cdylib` for wasm32 and an `rlib` for native tests. |
78| [jevhooks-rules/](jevhooks-rules/) | Chapters 11 and 12: the questions, the facts and the rules, as `rete` networks. No I/O; builds for wasm32 too. |
79| [jevhooks-daemon/](jevhooks-daemon/) | Chapters 13 and 14: the `jevhooks` binary. |
80
81← Previous: [Chapter 5, tests/](../plugin/tests/) · Up: [jevhooks](../) · Next: [Chapter 7, jevhooks-events/](jevhooks-events/) →