This guide helps AI agents implement and review db-sync features consistently across the client and the Cloudflare Worker. Keep changes scoped, follow the existing flow, and document any protocol or storage changes. Keep this document accurate (file names, paths, commands, and parameters).
src/main/frontend/config.cljssrc/main/frontend/worker/db_sync.cljssrc/main/frontend/worker/db_worker.cljssrc/main/frontend/handler/db_based/db_sync.cljsdeps/db-sync/src/logseq/db_sync/deps/db-sync/worker/README.md1) Define behavior: state the new capability, expected inputs/outputs, and compatibility requirements.
2) Update protocol first (if needed): change protocol.cljs and adjust server/client serialization in tandem.
3) Server changes: update worker.cljs, worker_core.cljs, storage.cljs, or cycle.cljs.
4) Client changes: update db_sync.cljs and thread APIs in db_worker.cljs.
5) Handler glue: add or adjust the entry points in handler/db_based/db_sync.cljs.
:db-sync/* keywords; add new keywords via logseq.common.defkeywords/defkeyword.ws(s) to /sync/:graph-id (client builds URL from config and appends ?token=... when available).tx payloads are Transit strings.{"type":"hello","client":"<repo-id>"}: initial hello; server responds with t.{"type":"pull","since":<t>}: request txs after since (defaults to 0).{"type":"tx/batch","t_before":<t>,"txs":["<tx-transit>", ...]}: upload batch.{"type":"ping"}: optional keepalive; server replies pong.{"type":"hello","t":<t>}: server hello with current t.{"type":"pull/ok","t":<t>,"txs":[{"t":<t>,"tx":"<tx-transit>"}...]}: pull response.{"type":"tx/batch/ok","t":<t>}: batch accepted.{"type":"changed","t":<t>}: broadcast that server state advanced; client should pull.{"type":"tx/reject","reason":"stale","t":<t>}: client tx based on stale t.{"type":"tx/reject","reason":"cycle","data":"<transit {:attr <kw> :server_values ...}>"}: cycle detected with server values.{"type":"tx/reject","reason":"empty tx data"|"invalid tx"}: invalid batch.{"type":"pong"}: keepalive response.{"type":"error","message":"..."}: invalid/unknown message.bb dev:db-sync-start runs the db-sync watcher, wrangler dev, and yarn watch with ENABLE_DB_SYNC_LOCAL=truebb dev:lint-and-testbb dev:db-sync-testbb dev:test -v logseq.db-sync.storage-test/fooclojure -M:cljs release db-sync:db-sync/* context keys.