The app now opens on a menu, which is the root page: "Hands free" first, "Agents" second. Agents is the 0.2.0 app unchanged. Hands free is the same agents, conversations and question path with one flag set: the microphone listens while the app is at rest and the app does not leave by itself. The mode is never remembered; every launch starts at the menu with the microphone closed, and double tap at Ready returns to the menu and closes it. Client: a loudness-only speech segmenter (core/vad.ts) cuts the stream into utterances; each goes to the bridge for a wake check. "Wendy, <q>" becomes a text turn to Wendy, with what was heard shown while she works. A name alone starts a recording that sends itself when the speaker stops. The status line starts with a dot for exactly as long as the microphone is open at rest. In wake mode every microphone open and close goes through one serialised reconciler; without the option the old path is untouched. Bridge: POST /v1/wake transcribes one utterance in memory and reports whether it BEGAN with an agent's name (first word of the display name, or an alias from HERMEVEN_AGENT_<ID>_WAKE). Exact match only; a near miss is reported as one word and never acted on. Creates no turn, stores nothing, returns and logs nothing that was not addressed to an agent. One check at a time per device, HERMEVEN_WAKE_CHECKS_PER_MINUTE (30). Docs: decision 0004, bridge API, security gaps 3c/3d, device plan D. The manifest's microphone description changed. Not reviewed, not deployed, not uploaded, not device-tested. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
108 lines
5.1 KiB
Markdown
108 lines
5.1 KiB
Markdown
# 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 --> built-in Whisper (in process), or an external endpoint
|
|
|-- 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.
|
|
|
|
```
|
|
MENU -> 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:
|
|
|
|
0. On the phone, before any of this: the app stores the request id in app storage and waits
|
|
for the host to confirm the write. No confirmation, no request.
|
|
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.
|
|
- A tapped capture ends by tap or cap. Only a recording started by an agent's name ends when
|
|
the speaker stops (`docs/decisions/0004-always-listening.md`).
|