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>
This commit is contained in:
Dan
2026-11-18 18:21:49 -08:00
co-authored by Claude Fable 5.2
commit 4687cc0114
79 changed files with 11685 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
import Database from 'better-sqlite3';
import { mkdirSync } from 'node:fs';
import { dirname } from 'node:path';
export type Db = Database.Database;
const MIGRATIONS: string[] = [
`
CREATE TABLE devices (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
profile TEXT NOT NULL,
token_hash TEXT NOT NULL UNIQUE,
created_at INTEGER NOT NULL,
token_expires_at INTEGER NOT NULL,
pairing_expires_at INTEGER NOT NULL,
revoked_at INTEGER,
last_seen_at INTEGER
);
CREATE TABLE pairing_codes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
code_hash TEXT NOT NULL UNIQUE,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
used_at INTEGER,
failed_attempts INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE conversations (
id TEXT PRIMARY KEY,
device_id TEXT NOT NULL REFERENCES devices(id),
-- Opaque reference into Hermes. Generated by the bridge, never accepted from a client.
hermes_session_id TEXT NOT NULL UNIQUE,
created_at INTEGER NOT NULL,
closed_at INTEGER
);
CREATE INDEX conversations_device ON conversations(device_id, closed_at);
CREATE TABLE turns (
request_id TEXT PRIMARY KEY,
device_id TEXT NOT NULL REFERENCES devices(id),
conversation_id TEXT NOT NULL REFERENCES conversations(id),
input_kind TEXT NOT NULL,
-- SHA-256 of metadata + input bytes: detects a reused request_id with a different payload.
input_fingerprint TEXT NOT NULL,
locale TEXT NOT NULL,
state TEXT NOT NULL,
outcome TEXT,
error_code TEXT,
error_message TEXT,
cancel_requested INTEGER NOT NULL DEFAULT 0,
hermes_idempotency_key TEXT NOT NULL,
hermes_run_id TEXT,
-- Exact Hermes request body, held only between "about to submit" and "run id persisted"
-- so a crash in that window can replay the same idempotent request. Cleared afterwards.
pending_body TEXT,
-- Result cache, cleared after the retention window. Hermes stays the transcript authority.
input_text TEXT,
answer_text TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
agent_started_at INTEGER,
approval_started_at INTEGER,
completed_at INTEGER,
transcribe_ms INTEGER,
agent_ms INTEGER
);
CREATE INDEX turns_conversation ON turns(conversation_id, state);
CREATE INDEX turns_state ON turns(state);
`,
];
export function openDb(path: string): Db {
if (path !== ':memory:') mkdirSync(dirname(path), { recursive: true });
const db = new Database(path);
db.pragma('journal_mode = WAL');
db.pragma('foreign_keys = ON');
db.pragma('busy_timeout = 5000');
migrate(db);
return db;
}
function migrate(db: Db): void {
const current = db.pragma('user_version', { simple: true }) as number;
for (let v = current; v < MIGRATIONS.length; v++) {
const sql = MIGRATIONS[v]!;
db.transaction(() => {
db.exec(sql);
db.pragma(`user_version = ${v + 1}`);
})();
}
}