01 The book metadata sidecar

A small flat JSON file next to a book:

  /Books/Dune.epub
  /Books/Dune.epub.meta.json   ->   { "myservice_id": "36835", "source": "myservice" }

Use it to remember which service book this file is, so later events and syncs can refer to it.

Who writes it
- A catalog download: "sidecar": { "path": "{dest}.meta.json", "body": "{\"myservice_id\":\"{id}\"}" }
- plugin.js: api.writeFile(bookPath + '.meta.json', b64(JSON.stringify({...})))
- You, by hand.

Who reads it
1. Event templates: {meta.myservice_id} for events that carry book (or path for book.downloaded).
2. require_meta filters (see above).
3. KOSync: with Send book metadata enabled in the KOSync settings, all fields are merged into the metadata object of every progress upload (it can't override filename, title, authors). A custom sync server can then route progress by metadata.myservice_id.

Rules
- Flat values only: strings, numbers, booleans. Nested values and null are ignored. {meta.*} sees strings and whole numbers. Decimals and booleans read as empty.
- <= 2 KB.
- Namespace your keys (bookfusion_id, not id). All plugins share one sidecar per book, and the last writer of a key wins.
- require_meta reads the sidecar when the event fires, so write it before the book is opened.
Reader file (.txt)