mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-19 23:14:25 +01:00
RtdbClaudeRelay against the contract fixture, ULID ids, uuid5 entry ids, withdraw on local log. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZHWP4KZ6x5TcXDBFC
1.9 KiB
1.9 KiB
The phone's side of the Claude relay
Code in app/lib/services/claude_relay_*.dart; the other half of the contract.
RtdbClaudeRelay implements the screen's ClaudeRelayClient; the wire is
claude_relay_wire.dart, gated by the fixture
(app/test/services/claude_relay_contract_test.dart). The fixture's
key_hex is the cipher key itself, which is what E2eKey.cipher() hands out
on both devices; the phone gets it through openDietGuardCipher, the same
keystore passphrase and header as the log sync (locked = SyncLockedException
= the lock glyph on the sparkle).
ridis a ULID made on the phone (newRequestId); the entry id isuuid5(entry_id_namespace, rid)(claudeEntryId), computed before any answer. A result whoseentry_iddiffers is refused, so undo (a tombstone on that id) and the logged row always address the entry the PC wrote.- The phone PUTs
requests/<rid>/reqwithcreated = {".sv": "timestamp"}, then lists the node's child keys (shallow: the photo is never re-read) every 1 s, every 5 s after 30 s. Noclaimwithin 3 s: queued (hourglass), the same stream keeps waiting, up to 15 min. Aresultis opened, the noderequests/<rid>is deleted, and the event is shown. - Fail closed, visibly (error glyph): a body that breaks section 2 (checked first, nothing is sent), a failed PUT, three failed polls in a row, a result that does not open or is malformed, an entry id mismatch, the node vanishing.
- Withdrawing. A local check-mark log while a request is in flight or queued
calls
cancel(rid): one read withX-Firebase-ETag, then aDELETEwithif-match. A claim written in between changes the ETag and turns the delete into a 412, so "unclaimed" is decided atomically. If it was claimed the PC will log the meal; that race is accepted. The phone keeps the stream open so the second meal still shows as a row with an undo instead of arriving unseen.