1# Chapter 7: jevhooks-events, the treaty
2
3Two programs that talk over a socket have to agree on words. If the mod
4sends `"PreToolUse"` and the daemon expects `"pre_tool_use"`, nothing
5crashes: the daemon just refuses the event, the mod reads the refusal as
6"no opinion", and the plugin quietly stops doing anything. That is the
7worst kind of bug, the kind that looks like everything is fine.
8
9This crate is the treaty both sides sign. It is a handful of Rust types,
10and both the mod and the daemon are compiled from them: the mod into
11JavaScript (chapter 9), the daemon natively (chapter 11). Rename a variant
12here and both sides change in the same build. They cannot disagree,
13because there is only one of each word.
14
15```mermaid
16flowchart LR
17  events["jevhooks-events<br/>HookEvent, Role, Verdict, Decision"]
18  events -- "compiled to wasm, then JS" --> modjs["plugin/hooks/jevhooks.js"]
19  events -- "compiled natively" --> daemon["plugin/bin/jevhooks"]
20  modjs -- "JSON on a Unix socket" --> daemon
21```
22
23It depends on `serde` and nothing else: no network, no files, no clock. That
24is not tidiness. The mod's copy has to run inside Claude Code as plain
25JavaScript, where none of those exist.
26
27> **Aside: serde.** If you come from JavaScript, `serde` is the part of
28> Rust that `JSON.stringify` and `JSON.parse` are built into. Putting
29> `#[derive(Serialize, Deserialize)]` on a type writes both directions for
30> you, and `#[serde(rename_all = "lowercase")]` decides that `Verdict::Ask`
31> travels as `"ask"`.
32
33> **Try it.** `cargo test -p jevhooks-events` runs its two tests: every
34> event is listed once, and an event's JSON name is its hook name
35> (`"PreToolUse"`, `"Stop"`).
36
37## For the people who maintain it
38
39The one place a word is *not* shared: the daemon's reply, a `Decision`, is
40read on the TypeScript side through `plugin/types/index.d.ts`, which
41mirrors it by hand (chapter 4).
42
43### In this folder
44
45| Path | What |
46| --- | --- |
47| [src/](src/) | Chapter 8: the types. |
48| [Cargo.toml](Cargo.toml) | The crate: `serde`, and `serde_json` for the tests. |
49
50← Previous: [Chapter 6, crates/](../) · Up: [crates](../) · Next: [Chapter 8, jevhooks-events/src/](src/) →