Files
hermeven/docs/architecture.md
T
DanandClaude Fable 5.2 4687cc0114 First vertical slice: Even client, bridge, contract v1, tests, docs
Client (apps/even-client): pure interaction reducer with generation-based
stale-result rejection, HUD renderer, measured pagination, Even Hub SDK
0.0.16 adapter, bridge HTTP client, phone pairing/status/diagnostics page.

Bridge (services/bridge): device pairing and revocable expiring credentials,
turn engine with idempotent submit, cancel, deadlines and restart recovery,
Hermes Runs API adapter, OpenAI-compatible STT adapter, operator CLI.

Contract (packages/contracts): versioned schemas, types and error codes.

Tests: 122 unit/integration (fakes), 6 simulator scenarios (Even Hub
simulator 0.9.5), 9 scenarios against a real Hermes v0.23.1 gateway with a
stub model. No real STT, real model or physical device has been exercised;
see docs/test-evidence.md and docs/device-test-plan.md.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 18:21:49 -08:00

4.8 KiB

Architecture

G2 mic / touch / HUD
        |  Bluetooth (Even's protocol, not ours)
Even phone app  --  WebView running apps/even-client (public Even Hub SDK)
        |  HTTPS, device credential, polling
services/bridge  (Fastify + SQLite)
        |-- STT adapter  -->  an OpenAI-compatible transcription endpoint you choose
        |-- Hermes adapter -->  Hermes API server (Runs API) for one configured profile

Who owns what

Concern Owner
Agent identity, memory, transcript, model, tools, approval policy Hermes
Device authorisation, request deduplication, turn lifecycle, deadlines Bridge
Microphone, gestures, HUD, app lifecycle Even runtime on the phone
Starting, cancelling, resetting, approving The user

The bridge stores references and a short-lived result cache, not a transcript. Question and answer text is erased from the bridge 15 minutes after a turn ends (configurable).

Packages

Path Role
packages/contracts Contract v1: JSON Schemas (TypeBox), types, stable error codes. Imported by both sides.
services/bridge HTTP API, pairing and credentials, turn engine, Hermes and STT adapters, operator CLI.
apps/even-client Pure state reducer, HUD renderer, pagination, Even adapter, bridge client, phone page.
tests/fakes Labelled fakes: Hermes Runs API, STT endpoint, glasses, stub model.
tests/integration Bridge over HTTP, and client-to-bridge end to end, against the fakes.
tests/simulator The real client in the official simulator.
tests/real-hermes The bridge against a real Hermes gateway with a stub model.

Client

core/reducer.ts is a pure function (state, event) -> (state, effects). It has no clock, no network and no randomness: request ids arrive inside events and work leaves as effects.

READY -> LISTENING -> TRANSCRIBING -> THINKING -> ANSWER
plus APPROVAL, ERROR, DISCONNECTED, CANCELLED, UNPAIRED

Every user action that starts, cancels or abandons something increments a generation counter. Each asynchronous effect carries the generation it started under, and the reducer drops any event whose generation is not current or whose request id is not the current one. That is the single mechanism behind "a late result must not replace a newer answer or resurrect a cancelled screen".

core/controller.ts runs the effects: microphone capture, submit with retry, polling, cancel, conversation creation, persistence. device/port.ts is the seam to the glasses; the Even adapter and the test fake both implement it.

Bridge turn lifecycle

accepted -> transcribing -> thinking -> done
                               |-> approval_required -> thinking
                               |-> cancelling -> done

done always carries an outcome: succeeded, incomplete, failed, cancelled or unknown.

Order of operations for one turn:

  1. Validate, authenticate, check the conversation belongs to the device and is open, and that no other turn is running in it. Insert the turn row keyed by the client's request id. A repeat of the same request id returns the existing turn.
  2. Audio only: wrap the PCM as WAV in memory, transcribe, drop the audio.
  3. Persist the exact Hermes request body, then send it with Idempotency-Key.
  4. Persist the returned run id and erase the stored body.
  5. Poll the run until it is terminal, a deadline passes, or a cancel is requested.

Why the order matters: after step 3 a crash can always be recovered by re-sending the identical body under the same key (Hermes returns the original run), and before step 3 nothing has reached Hermes, so failing the turn is provably safe.

How ambiguous situations are classified

Situation Outcome Retryable
STT error, timeout or empty transcript failed yes: nothing reached Hermes
Bridge restarted before step 3 failed (interrupted_before_agent) yes
Connection to Hermes refused on every attempt failed (agent_unreachable) yes
Hermes answered 4xx failed (agent_rejected) no
Request sent, no usable reply, deadline passed unknown no
Hermes reports unknown or no longer knows the run unknown no
Deadline passed, stop requested, Hermes confirmed cancelled (agent_timeout) no
Stop requested, not confirmed within the grace period unknown no
Cancel requested but the run completed first succeeded, cancel_requested: true n/a

"Retryable" means a deliberate new question by the user is safe. Nothing is ever replayed automatically under a new request id.

Deliberate limits of this slice

  • One process, one profile, one active conversation per device.
  • Polling only; no streaming.
  • A second question while one is running in the same conversation is refused (conversation_busy), not queued.
  • Capture ends by tap or cap. There is no end-of-speech detection.