# Cortex client protocol

Source: https://usecns.dev/contract-cortex/

## 4. `Cortex` Supervisory Switchboard & Client Protocol

The daemon exposes HTTP and WebSocket interfaces for supervisory clients. The planned macOS and iOS apps (`clients/macos`, `clients/ios`) remain **specified designs, not shipped applications**. Client designs are not the authority for the daemon's implemented routes. Use the [Cortex interface reference](https://usecns.dev/commands-cortex/) for the source-reviewed route, tool, configuration and error contracts.

1. **Owner-initiated device pairing (`CX-XXXXXX`)**:
   * An authenticated owner sends `POST /api/v1/identity/pair/initiate` with the intended principal/surface and optional host URL and lifetime. The response is HTTP 201 with `ok`, protocol/daemon versions and `challenge`. Lifetime defaults to 60 seconds and is clamped to 5–600 seconds.
   * An unpaired client sends `POST /api/v1/identity/pair/exchange` with `code`, optional `deviceName` and `surface`. Successful exchange returns HTTP 200 with the binding/token and versions; invalid, expired or reused codes return 400. Protect the code and issued token. These are not `/api/v1/pairing/request` and `/approve` endpoints.
2. **Bootstrap (`GET /api/v1/bootstrap`)**:
   * Select `seatId` and `conversationId` explicitly. The bundle includes `protocolVersion: 1`, daemon version, seats, active seat/conversation IDs, conversations, task graph, snapshot, entries, `latestEntryId`, switchboard state and identity data. `lite=1` omits the additional model catalog and ingress-status sections.
   * `afterEntryId` requests durable entries after a saved cursor and sets `entriesDelta`. `focus=1` and `stepUp=1` can change supervisory focus; they are not read-only selectors. See the reference for aliases and role constraints.
3. **Cursor-aware WebSocket subscription (`/ws`)**:
   * Authenticate the upgrade and select `seatId`, `conversationId` and optional `sinceEntryId`. The first message is `initial_snapshot`, with event/conversation snapshots and task graph; a cursor also adds `deltaEntries`. Clients can later send a `subscribe` message to select another conversation.
   * Replay applies to durable conversation entries, not every notification or external side effect. Retain cursors per seat/conversation, deduplicate by entry ID and recover current state on reconnect. Voice uses its own `/ws/voice` surface; this is not a replay log of all voice or model-server telemetry.
4. **Supervisory controls**:
   * Supported surfaces recognize `$focus` / `$tree`, `$focus <seatId>` / `$seat <seatId>`, and `$up` / `$back`. Channel/switchboard controls accept a `top` destination; the browser composer currently treats upward commands, including `top`, as one step. These change or inspect navigation. CLI operations such as `abort`, `fork` and model configuration are documented separately; a `$` prefix does not make every CLI verb a switchboard control.

---