keeps: Datomic-aware piece lookup + upsert so new pieces are keepable
Since KIDLISP_DATOMIC=on is enabled on lith, new pieces get stored by
store-kidlisp via the Datomic sidecar (store-kidlisp-datomic.mjs), not in
MongoDB's `kidlisp` collection. Any Mongo-only read path then reports
"Piece '$code' not found" when the user tries to keep/rebake/sync a
freshly-created piece. Reported against $r94 today (seen in the DB as
present via /api/store-kidlisp?code=r94, absent when queried directly in
Mongo).
Adds backend/kidlisp-read.mjs :: loadKidlispPiece(database, code):
- Reads from the sidecar when the feature flag is on.
- Overlays the Mongo row on top so rebake-era fields (ipfsMedia,
mediaHistory, kept, tezos, pendingRebake) keep working for pieces
already kept under the legacy flow.
- Falls back to a direct Mongo read when Datomic is off or the sidecar
call fails.
Wires the helper into every keep-flow entrypoint that previously read
Mongo directly:
- keep-prepare.mjs (initial validate)
- keep-prepare-background.mjs (bake pipeline)
- keep-confirm.mjs (mint confirm)
- keep-update.mjs (on-chain metadata sync)
- keep-update-confirm.mjs (sync confirm)
Also marks the Mongo updateOne calls in keep-prepare-background,
keep-confirm, and keep-update-confirm as { upsert: true } so the first
bake/mint/sync of a Datomic-only piece creates a Mongo row to receive
ipfsMedia / kept / tezos fields, instead of silently no-op'ing because
no matching document exists.
Leaves kidlisp-keep.mjs alone — it queries the unrelated `kidlisp-codes`
legacy collection.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>