# EVE Cortical Steering SDK — Agent Operating Instructions (`AGENTS.md`)

You are operating in an environment equipped with **Eve** (`https://evelabs.info/v1`, SDK `v2.5.3`), a real-time biological cortical salience and trajectory-steering daemon coupled to the operator's 4-channel dry EEG headband (Interaxon Muse 2: `TP9, AF7, AF8, TP10` @ 256 Hz, with full `p50` hardware telemetry conditioned server-side).

Zero-install browser pairing & live `mtop` monitor are available at `https://evelabs.info/v1/app`, and Remote Streamable-HTTP MCP is available at `https://evelabs.info/v1/mcp` (working in both `claude.ai` browser chat and Claude Desktop/Code without local scripts). No upstream LLM API keys are ever shared: your agent retains full control of its own LLM credentials and sends only `(live_eeg_samples, decision_prompt, candidate_branches)` (or references the active streaming `session_id`) to `POST https://evelabs.info/v1/steer`.

---

## 1. Architecture, Security & Isolation Invariants

1. **Thin Local BLE GATT Relay (`eve_muse_daemon.py`):**
   - Pairs directly with the Muse 2 headband over BLE (`0000fe8d-0000-1000-8000-00805f9b34fb`), streams end-to-end encrypted (`ChaCha20-Poly1305`) 256 Hz raw `p50` frames (`TP9, AF7, AF8, TP10, RightAUX` + 12-bit `REF/DRL` + `PPG` + `IMU`) to `wss://evelabs.info/v1/stream`, and atomically updates `~/.eve/live_eeg.json` every 250 ms.
2. **Immutable Runtime & Passive Update Notifier (Zero Self-Modifying Code):**
   - Neither `eve_muse_daemon.py`, `eve_sdk.py`, nor `eve_mcp.py` contains any code to download archives, overwrite files in `~/.eve/sdk/`, or self-restart (`os.execv`).
   - When a newer SDK release exists, the server includes version metadata that is surfaced strictly as a passive read-only `update_available` notice in `~/.eve/live_eeg.json`, `eve status`, and `eve update`.
   - Running `~/.eve/sdk/eve update` is a 100% read-only version and SHA-256 notifier (`files_modified: false`) that prints the release version and SHA-256 digest so the operator (or their local coding agent) can download and inspect `eve-agent-sdk.tar.gz` before manually replacing `~/.eve/sdk/`.
3. **Server-Side Signal Conditioning & Cortical Reranker (`POST https://evelabs.info/v1/steer`):**
   - Performs proprietary anti-rail conditioning, noise-witness cancellation, hardware seating verification, and per-person $k=16$ adaptive branch reranking on the server, returning pure JSON identifying the winning trajectory.
4. **Zero Credential Leakage:**
   - Your upstream OpenAI / Anthropic / Google / local model keys never leave this machine.

---

## 2. Seamless Onboarding, Diagnostics & Passive Update Check

```bash
# 1. One-command diagnostic preflight (checks deps, key, SDK version, BLE & DRL lock)
~/.eve/sdk/eve doctor

# 2. Start background BLE daemon (connects Muse 2 over Bluetooth; never self-modifies)
~/.eve/sdk/eve daemon --background

# 3. Live terminal EEG & electrode seating monitor (like htop/mtop for Muse 2)
~/.eve/sdk/mtop

# 4. Launch localhost (127.0.0.1:8765) graphical 4-ch EEG oscilloscope & headband GUI
~/.eve/sdk/eve gui

# 5. Check live session, seating/DRL lock, calibration status & passive update notice
~/.eve/sdk/eve status

# 6. Read-only update notifier (checks version & SHA-256; never modifies files on disk)
~/.eve/sdk/eve update

# 7. Register native MCP server in Claude Code / MCP clients
claude mcp add eve -- python3 ~/.eve/sdk/eve_mcp.py
```

---

## 3. Cortical Preference Selection Contract

### A. Candidate Formulation (`2-5` Substantive Options)
- **Orient First, Then Consult Eve:** Inspect 1–2 relevant files or state first so your candidate branches are grounded in real context, then call `eve_steer_branches` (via MCP or `~/.eve/sdk/eve steer`) whenever an open question or task leaves 2–5 distinct, well-reasoned directions open where choosing between them is a judgment call (framing, angle, architecture, or which approach to take first).
- **Sound Options Only:** Every candidate ($N \in \{2..5\}$, ~20–65 words each, with short `candidate_labels`) should be a substantive option that is factually and methodologically sound on its own merits. Avoid padding filler options when 2–3 strong options capture the fork, and avoid register-only rewordings or meta-options about the headband.

### B. Turn-Scoped Execution (`winning_index`) & Redirect Calibration
- **Turn-Scoped Direction:** Each reading is turn-specific—treat `winning_index` as the user's preferred direction for the current turn and go with it. A brief mention is fine ("Going with the X angle"); a long explanation of the EEG isn't needed. If `signal.ok` is `false`, continue with your own judgment without stopping.
- **Redirects Improve Calibration:** Whenever the user confirms or redirects to another option, log it via `eve_calibrate_outcome` (`--steer-id` + `--chosen-index` / `--chosen-text`) so their personal decoder improves, then run a fresh steer when the next open fork arises.

---

## 4. Pure-JSON CLI & Python SDK Reference

### A. Steer $N$ Candidate Branches via CLI (`~/.eve/sdk/eve steer`)
```bash
~/.eve/sdk/eve steer \
  --prompt "How should we structure the local ring buffer and API retry logic?" \
  --label "Atomic mmap ring + exponential backoff" \
  --branch "Use a lock-free atomic rename over a 2048-sample JSON ring buffer with exponential backoff on HTTP 502/503." \
  --label "SQLite WAL local queue + batch flush" \
  --branch "Write every 12-sample BLE frame into a local SQLite WAL table and flush 2-second windows asynchronously." \
  --label "In-memory asyncio queue + fail-fast" \
  --branch "Keep samples strictly in an asyncio ring deque and drop stale windows immediately on network timeout."
```

### B. Python SDK (`from eve_sdk import EveClient`)
```python
from eve_sdk import EveClient

eve = EveClient()  # Reads ~/.eve/config.json and ~/.eve/live_eeg.json automatically
res = eve.steer(
    prompt="Select database indexing strategy",
    candidates=[
        "Partial B-tree index on active status column",
        "Covering composite index on (tenant_id, created_at)",
        "Materialized rollup table refreshed on write",
    ],
    candidate_labels=["Partial B-Tree", "Composite Covering", "Materialized Rollup"],
)
winner = res["winning_candidate"]
```

### C. Outcome Calibration (`k=16` Adaptive Calibration via `steer_id`) & `HTTP 402` Quota Handling
- **Outcome Confirmation (`eve calibrate --steer-id`):** Whenever the operator confirms or overrides a decision outcome, record the ground-truth outcome against that `steer_id`:
  ```bash
  ~/.eve/sdk/eve calibrate --steer-id str_a1b2c3d4e5f6 --chosen-index 0
  ```
- **Quota Handling (`HTTP 402`):** If the API returns `HTTP 402` (`"error": "quota_exceeded"`), surface the returned `message` and `quota` JSON directly to the operator.
