From 9394c249ad3e7bdf5d08b12a2cc3e2d2848aaadb Mon Sep 17 00:00:00 2001 From: Dan Date: Sat, 21 Nov 2026 16:08:11 -0800 Subject: [PATCH] Choose an agent with a swipe at Ready (0.2.0) Bridge: an owner-configured list of agents (HERMEVEN_AGENTS). Each extra agent is another profile of the same Hermes gateway, reached at /p/ with that profile's own key. GET /v1/agents lists ids and names; POST /v1/conversations takes an optional agent_id checked against the list. A conversation belongs to one agent (migration v3) and its turns are submitted, polled and stopped at that agent. /v1/device is unchanged so clients built earlier keep working. Client: at Ready a swipe moves between agents; the name is shown through the exchange; each agent keeps its own conversation; a follow-up goes to the agent that answered. Reopened within the conversation window it opens on the last agent, otherwise on the default. With one agent, or a bridge without /v1/agents, nothing changes. Also: contract section G, server survey and key evidence, the 0.1.2 upload, and the CODY-020 correction. Not reviewed, not deployed, not uploaded. Co-Authored-By: Claude Fable 5.2 --- README.md | 4 +- apps/even-client/app.template.json | 2 +- apps/even-client/src/core/controller.ts | 131 +++- apps/even-client/src/core/hud.ts | 16 +- apps/even-client/src/core/reducer.ts | 54 +- apps/even-client/src/net/bridgeClient.ts | 13 +- apps/even-client/test/reducer.test.ts | 60 ++ deploy/bridge.env.example | 8 + docs/bridge-api.md | 23 +- ...droplet-deployment-and-first-device-run.md | 17 + docs/evidence/droplet/2026-11-21.md | 35 ++ docs/test-evidence.md | 8 +- packages/contracts/src/schemas.ts | 22 +- services/bridge/src/app.ts | 9 +- services/bridge/src/config.ts | 63 +- services/bridge/src/db.ts | 5 + services/bridge/src/server.ts | 18 +- services/bridge/src/turns.ts | 68 ++- tests/fakes/fakeHermes.ts | 42 +- tests/integration/agents.test.ts | 561 ++++++++++++++++++ 20 files changed, 1117 insertions(+), 42 deletions(-) create mode 100644 tests/integration/agents.test.ts diff --git a/README.md b/README.md index f936fba..4b3b042 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ the implementer read from the server's log, and what Cody reproduced independent | Path | State | |---|---| | Client, bridge and contract | Implemented. | -| Automated tests with fakes (233) | Passing. | +| Automated tests with fakes (296) | Passing. | | Client in Even's official simulator | Passing (7 scenarios). Simulator only. | | Bridge against a real Hermes gateway | Passing (9 scenarios) with a **stub model**. | | Built-in speech-to-text (Whisper, in the bridge) | Passing (11 scenarios) on a real speech recording, including with no network. Not yet on audio from the glasses. | @@ -28,6 +28,7 @@ the implementer read from the server's log, and what Cody reproduced independent | Ring, paging, contextual menu, cancel, relaunch with the pairing kept, the system exit dialog on the device | **Not run.** | | Locked phone | First success on 2026-11-21 with the beta build: launched by voice ("Hey Even, open Pepper") and a spoken question answered with the phone locked (Dan's report). The specification's ten-cycle acceptance run has **not** been done. | | Leaving the glasses when idle | 0.1.1 on the device (2026-11-21, Dan's report): after one gesture the app left by itself and Telegram notifications returned to the lenses; after a voice launch with nothing touched it did **not** leave. 0.1.2 starts the countdown however the app was opened; tested with fakes and the simulator, **not installed on the device.** | +| More than one agent (swipe at Ready to choose) | Implemented in 0.2.0 and tested with fakes. On the server, one real question was answered by a second Hermes profile through its own address and key (`docs/evidence/droplet/2026-11-21.md`). **Not deployed, not installed on the device.** | | Real tools and approval flow | One tool use seen (a Telegram message, reported by Dan). The approval path has **not** been exercised against a real agent. | | Sustained load, backups, monitoring, upgrades on the server | **Not verified.** | | Clean-host install (`deploy/install.sh`) | Proven on a disposable Ubuntu 24.04 container with systemd (`tests/deploy/runbook-proof.sh`), not on a second real server. | @@ -78,6 +79,7 @@ instructions, including building for the glasses, are in `docs/setup.md`. | Swipe down / up | Next / previous page of the answer. | | Tap on an answer | Ask a follow-up in the same conversation. | | Double tap | Cancel what is in progress, or go back. At "Ready" it opens the system exit dialog. | +| Swipe at Ready | From 0.2.0, when the bridge offers more than one agent: choose who to talk to. The name is shown; on an answer a swipe still turns the page. | | Leave it alone | From 0.1.1: Pepper leaves the glasses by herself (20 s after an answer, 30 s at Ready, 10 s after an error), so the normal screen and notifications return. Call her back from the glasses' menu or with "Hey Even, open Pepper". | | Tap, then long press | The system menu, with "New conversation" and "Cancel request". | diff --git a/apps/even-client/app.template.json b/apps/even-client/app.template.json index 3ec05fc..565adb2 100644 --- a/apps/even-client/app.template.json +++ b/apps/even-client/app.template.json @@ -2,7 +2,7 @@ "package_id": "xylo.hermeven", "edition": "202601", "name": "Pepper", - "version": "0.1.2", + "version": "0.2.0", "min_sdk_version": "0.0.16", "entrypoint": "index.html", "permissions": [ diff --git a/apps/even-client/src/core/controller.ts b/apps/even-client/src/core/controller.ts index 0767883..0ed2005 100644 --- a/apps/even-client/src/core/controller.ts +++ b/apps/even-client/src/core/controller.ts @@ -5,7 +5,7 @@ import { BridgeApiError, BridgeClient, BridgeNetworkError } from '../net/bridgeC import { BODY_BOX, HUD, renderHud } from './hud.ts'; import { paginate, type MeasureLines } from './paginate.ts'; import { toPlainText } from './plaintext.ts'; -import { initialState, reduce, type AppEvent, type AppState, type Effect, type HudError } from './reducer.ts'; +import { currentAgent, initialState, reduce, type Agent, type AppEvent, type AppState, type Effect, type HudError } from './reducer.ts'; const STORAGE_KEY = 'hermeven.v1'; @@ -26,6 +26,43 @@ interface Stored { activeCancelled: boolean; /** When the last turn in `conversationId` finished (ms since epoch), if known. */ lastTurnAt?: number; + /** + * The agent `conversationId` and `lastTurnAt` belong to: the one questions go to. Absent = + * the default agent. + */ + agentId?: string; + /** The same two values for every other agent that has been talked to, by agent id. */ + others?: Record; + /** The agent list as the bridge last gave it, used if the bridge cannot be asked at start. */ + agents?: Agent[]; +} + +interface AgentThread { + conversationId: string | null; + lastTurnAt?: number; +} + +const DEFAULT_AGENT = 'default'; + +function validAgents(value: unknown): Agent[] | undefined { + if (!Array.isArray(value)) return undefined; + const agents = value.filter( + (a): a is Agent => !!a && typeof (a as Agent).id === 'string' && typeof (a as Agent).name === 'string' && (a as Agent).name.length <= 24, + ); + return agents.length === value.length && agents.length <= 16 ? agents.map(({ id, name }) => ({ id, name })) : undefined; +} + +function validThreads(value: unknown): Record | undefined { + if (!value || typeof value !== 'object') return undefined; + const out: Record = {}; + for (const [id, thread] of Object.entries(value as Record>)) { + if (!thread || typeof thread !== 'object') continue; + out[id] = { + conversationId: typeof thread.conversationId === 'string' ? thread.conversationId : null, + lastTurnAt: typeof thread.lastTurnAt === 'number' ? thread.lastTurnAt : undefined, + }; + } + return out; } export interface DiagEntry { @@ -238,6 +275,8 @@ export class Controller { } } } + const agents = this.stored ? await this.loadAgents() : []; + if (this.stored) this.settleStartingAgent(agents); // A turn the user had abandoned is not shown again; its cancel is simply delivered now. const abandoned = this.stored?.activeCancelled ? this.stored.activeRequestId : null; this.dispatch({ @@ -247,10 +286,87 @@ export class Controller { captureMaxSeconds, resumeRequestId: abandoned ? null : (this.stored?.activeRequestId ?? null), storageFault: this.storageFault, + agents, + agentId: this.stored?.agentId ?? null, }); if (abandoned) void this.cancelTurn(abandoned); } + // ------------------------------------------------------------------ agents + + /** + * The agents the bridge offers. A single agent, or a bridge from before agent selection + * (`not_found`), gives an empty list: nothing about agents is then shown or sent. If the + * bridge cannot be asked right now, the list it gave last time is used. + */ + private async loadAgents(): Promise { + if (!this.client || !this.stored) return []; + let agents: Agent[]; + try { + const listed = (await this.client.agents()).agents; + agents = listed.length > 1 ? listed.map(({ id, name }) => ({ id, name })) : []; + } catch (err) { + if (err instanceof BridgeApiError && err.body.code === 'not_found') agents = []; + else { + this.note('agents', `agent list not available: ${describe(err)}`); + return this.stored?.agents ?? []; + } + } + if (this.stored && JSON.stringify(this.stored.agents ?? []) !== JSON.stringify(agents)) { + this.stored = { ...this.stored, agents }; + void this.save(); + } + return agents; + } + + /** Make `agentId` the stored current agent, swapping in its own conversation. No I/O. */ + private swapStoredAgent(agentId: string): void { + if (!this.stored) return; + const from = this.stored.agentId ?? DEFAULT_AGENT; + if (from === agentId) return; + const others = { ...(this.stored.others ?? {}) }; + others[from] = { conversationId: this.stored.conversationId, lastTurnAt: this.stored.lastTurnAt }; + let thread: AgentThread = others[agentId] ?? { conversationId: null }; + delete others[agentId]; + // The same rule as at start: after a long silence with that agent, the next question to it + // starts a new conversation. + if (thread.conversationId && thread.lastTurnAt !== undefined && this.now() - thread.lastTurnAt > this.conversationGapMs) { + thread = { conversationId: null, lastTurnAt: thread.lastTurnAt }; + } + this.stored = { ...this.stored, agentId, conversationId: thread.conversationId, lastTurnAt: thread.lastTurnAt, others }; + } + + /** + * Which agent the app opens on. It reopens on the agent last talked to only while that + * conversation is still current (the same window that decides whether a conversation + * continues); otherwise, or if that agent is no longer offered, it opens on the default. + * A turn still in flight keeps its agent. + */ + private settleStartingAgent(agents: Agent[]): void { + if (!this.stored) return; + const current = this.stored.agentId ?? DEFAULT_AGENT; + if (current === DEFAULT_AGENT) return; + if (this.stored.activeRequestId) return; + const offered = agents.some((a) => a.id === current); + const recent = this.stored.lastTurnAt !== undefined && this.now() - this.stored.lastTurnAt <= this.conversationGapMs; + if (offered && recent) return; + this.note('agents', offered ? 'last agent was a while ago: opening on the default' : 'last agent is no longer offered: opening on the default'); + this.swapStoredAgent(DEFAULT_AGENT); + void this.save(); + } + + /** A swipe at Ready: move to the next or previous agent. Does nothing unless there is a choice. */ + private cycleAgent(delta: 1 | -1): void { + const agents = this.state.agents; + if (this.state.phase !== 'ready' || agents.length < 2 || !this.stored) return; + const index = agents.findIndex((a) => a.id === currentAgent(this.state)?.id); + const next = agents[(Math.max(0, index) + delta + agents.length) % agents.length]!; + this.swapStoredAgent(next.id); + void this.save(); + this.note('agents', `now talking to ${next.id}`); + this.dispatch({ type: 'agent_selected', agentId: next.id, conversationId: this.stored.conversationId }); + } + /** Stop for good: every pending retry and poll loop winds down and nothing more is drawn or emitted. */ async stop(): Promise { this.stopped = true; @@ -315,7 +431,8 @@ export class Controller { } catch (err) { this.note('bridge', `status check failed: ${describe(err)}`); } - this.dispatch({ type: 'init', paired: true, conversationId: null, captureMaxSeconds, resumeRequestId: null }); + const agents = await this.loadAgents(); + this.dispatch({ type: 'init', paired: true, conversationId: null, captureMaxSeconds, resumeRequestId: null, agents, agentId: null }); } /** Disconnect: revoke the credential on the bridge, then clear everything held locally. */ @@ -602,7 +719,9 @@ export class Controller { const client = this.client; const promise = this.createChain.then(async () => { if (!client || this.stopped || epoch !== this.state.conversationEpoch) throw new StaleConversationError(); - const created = await client.createConversation(); + // Named only when the bridge offered a choice; captured now, and the epoch check below + // drops the result if the user has moved to another agent meanwhile. + const created = await client.createConversation(this.state.agents.length ? (currentAgent(this.state)?.id ?? DEFAULT_AGENT) : undefined); // Checked BEFORE anything is stored: a result for a conversation the user has since // replaced (or for a pairing that has ended) is dropped, not persisted. if (this.stopped || epoch !== this.state.conversationEpoch || this.client !== client) throw new StaleConversationError(); @@ -843,8 +962,11 @@ export class Controller { this.heldPress = null; return this.dispatch({ type: 'back' }); case 'swipe_down': + // At Ready a swipe chooses the agent; on an answer it turns the page. + if (this.state.phase === 'ready' && this.state.agents.length > 1) return this.cycleAgent(1); return this.dispatch({ type: 'next_page' }); case 'swipe_up': + if (this.state.phase === 'ready' && this.state.agents.length > 1) return this.cycleAgent(-1); return this.dispatch({ type: 'prev_page' }); case 'menu': if (event.itemId === MENU_ITEM.NEW_CONVERSATION) return this.dispatch({ type: 'new_conversation' }); @@ -972,6 +1094,9 @@ export class Controller { activeRequestId: typeof parsed.activeRequestId === 'string' ? parsed.activeRequestId : null, activeCancelled: parsed.activeCancelled === true, lastTurnAt: typeof parsed.lastTurnAt === 'number' ? parsed.lastTurnAt : undefined, + agentId: typeof parsed.agentId === 'string' ? parsed.agentId : undefined, + others: validThreads(parsed.others), + agents: validAgents(parsed.agents), }; } catch { return null; diff --git a/apps/even-client/src/core/hud.ts b/apps/even-client/src/core/hud.ts index 6b14524..aa48d09 100644 --- a/apps/even-client/src/core/hud.ts +++ b/apps/even-client/src/core/hud.ts @@ -1,4 +1,4 @@ -import type { AppState } from './reducer.ts'; +import { currentAgent, type AppState } from './reducer.ts'; /** * HUD geometry. Canvas size and line height are documented by Even @@ -43,6 +43,8 @@ function clock(seconds: number): string { /** Pure: the complete HUD text for a state at a moment in time. */ export function renderHud(state: AppState, nowMs: number): HudFrame { + // With more than one agent on offer, every screen of an exchange says who it is with. + const agent = state.agents.length > 1 ? currentAgent(state) : undefined; switch (state.phase) { case 'unpaired': if (state.storageFault) { @@ -54,6 +56,12 @@ export function renderHud(state: AppState, nowMs: number): HudFrame { return { body: 'Hermeven\n\nNot connected.\nOpen Hermeven on your phone to pair.', status: 'Double-tap: exit' }; case 'ready': + if (agent) { + return { + body: state.notice ? `${agent.name}\n\n${state.notice}.` : `${agent.name}\n\nReady.`, + status: 'Tap: ask · Swipe: agent · 2×: exit', + }; + } return { body: state.notice ? `Hermeven\n\n${state.notice}.` : 'Hermeven\n\nReady.', status: 'Tap: ask · Double-tap: exit', @@ -63,7 +71,7 @@ export function renderHud(state: AppState, nowMs: number): HudFrame { const elapsed = state.captureStartedAt === null ? 0 : (nowMs - state.captureStartedAt) / 1000; const cap = state.captureMaxSeconds; return { - body: `Listening…\n\nRecording stops by itself after ${cap} seconds.`, + body: `${agent ? `${agent.name} is listening…` : 'Listening…'}\n\nRecording stops by itself after ${cap} seconds.`, status: `● REC ${clock(elapsed)} / ${clock(cap)} · Tap or release: send · 2×: cancel`, }; } @@ -72,7 +80,7 @@ export function renderHud(state: AppState, nowMs: number): HudFrame { return { body: 'Transcribing…', status: 'Double-tap: cancel' }; case 'thinking': - return { body: 'Thinking…', status: 'Double-tap: cancel' }; + return { body: agent ? `${agent.name} is thinking…` : 'Thinking…', status: 'Double-tap: cancel' }; case 'approval': return { @@ -85,7 +93,7 @@ export function renderHud(state: AppState, nowMs: number): HudFrame { const page = state.pages[state.pageIndex] ?? ''; const position = total > 1 ? `${state.pageIndex + 1}/${total} · Swipe: page · ` : ''; const partial = state.partial ? 'PARTIAL · ' : ''; - return { body: page, status: `${partial}${position}Tap: ask` }; + return { body: page, status: `${partial}${position}${agent ? `${agent.name} · ` : ''}Tap: ask` }; } case 'cancelled': diff --git a/apps/even-client/src/core/reducer.ts b/apps/even-client/src/core/reducer.ts index ea26640..f6715e3 100644 --- a/apps/even-client/src/core/reducer.ts +++ b/apps/even-client/src/core/reducer.ts @@ -29,8 +29,21 @@ export interface HudError { retryable: boolean; } +/** An agent the bridge lets this device talk to. */ +export interface Agent { + id: string; + name: string; +} + export interface AppState { phase: Phase; + /** + * The agents the bridge offers, default first. Empty when there is only one (or the bridge + * predates agent selection): nothing about agents is then shown or sent. + */ + agents: Agent[]; + /** The agent questions go to. Null = the default (the first in `agents`). */ + agentId: string | null; /** * Bumped whenever the user starts, cancels or abandons something. Every * asynchronous effect carries the generation it was issued under, and an @@ -64,6 +77,8 @@ export interface AppState { export const initialState: AppState = { phase: 'unpaired', + agents: [], + agentId: null, generation: 0, conversationId: null, conversationEpoch: 0, @@ -82,7 +97,18 @@ export const initialState: AppState = { }; export type AppEvent = - | { type: 'init'; paired: boolean; conversationId: string | null; captureMaxSeconds: number; resumeRequestId: string | null; storageFault?: boolean } + | { + type: 'init'; + paired: boolean; + conversationId: string | null; + captureMaxSeconds: number; + resumeRequestId: string | null; + storageFault?: boolean; + agents?: Agent[]; + agentId?: string | null; + } + /** The user picked another agent (a swipe at Ready). `conversationId` is that agent's own, if it has one. */ + | { type: 'agent_selected'; agentId: string; conversationId: string | null } | { type: 'unpaired' } /** Semantic actions. `freshId` is a new UUID supplied by the caller in case a turn starts. */ | { type: 'activate'; freshId: string } @@ -126,6 +152,12 @@ export interface Step { const IDLE: ReadonlySet = new Set(['ready', 'answer', 'error', 'cancelled']); const IN_FLIGHT: ReadonlySet = new Set(['transcribing', 'thinking', 'approval']); +/** The agent questions go to now, or undefined when the bridge offers no choice. */ +export function currentAgent(state: AppState): Agent | undefined { + if (state.agents.length === 0) return undefined; + return state.agents.find((a) => a.id === state.agentId) ?? state.agents[0]; +} + function clearTurn(state: AppState): AppState { return { ...state, @@ -169,6 +201,8 @@ export function reduce(state: AppState, event: AppEvent): Step { conversationId: event.conversationId, conversationEpoch: state.conversationEpoch + 1, storageFault: event.storageFault === true, + agents: event.agents ?? [], + agentId: event.agentId ?? null, }; if (!event.paired) return same({ ...base, phase: 'unpaired' }); if (event.resumeRequestId) { @@ -182,6 +216,24 @@ export function reduce(state: AppState, event: AppEvent): Step { return same({ ...base, phase: 'ready' }); } + case 'agent_selected': { + // Only from Ready: never while something is recording, in flight or on screen. Each agent + // has its own conversation, so the conversation is swapped with it, under a new epoch so a + // conversation still being created for the previous agent cannot land on this one. + if (state.phase !== 'ready') return same(state); + if (!state.agents.some((a) => a.id === event.agentId)) return same(state); + if (event.agentId === currentAgent(state)?.id) return same(state); + return same({ + ...clearTurn(state), + phase: 'ready', + generation: state.generation + 1, + agentId: event.agentId, + conversationId: event.conversationId, + conversationEpoch: state.conversationEpoch + 1, + creatingConversation: false, + }); + } + case 'unpaired': { const effects: Effect[] = state.phase === 'listening' ? [{ type: 'discard_capture' }] : []; return { diff --git a/apps/even-client/src/net/bridgeClient.ts b/apps/even-client/src/net/bridgeClient.ts index 98c0cf3..95daedc 100644 --- a/apps/even-client/src/net/bridgeClient.ts +++ b/apps/even-client/src/net/bridgeClient.ts @@ -1,6 +1,7 @@ import { AUDIO_FORMAT, check, + AgentsResponse, ConversationResponse, DeviceCredential, DeviceStatusResponse, @@ -135,8 +136,16 @@ export class BridgeClient { return this.call(RevokeResponse, 'DELETE', '/v1/device'); } - createConversation(): Promise { - return this.call(ConversationResponse, 'POST', '/v1/conversations', { json: { schema_version: SCHEMA_VERSION } }); + /** The agents this device may talk to. A bridge from before agent selection answers `not_found`. */ + agents(): Promise { + return this.call(AgentsResponse, 'GET', '/v1/agents'); + } + + /** `agentId` is sent only when given, so a bridge from before agent selection still accepts the request. */ + createConversation(agentId?: string): Promise { + return this.call(ConversationResponse, 'POST', '/v1/conversations', { + json: agentId === undefined ? { schema_version: SCHEMA_VERSION } : { schema_version: SCHEMA_VERSION, agent_id: agentId }, + }); } submitText(args: { requestId: string; conversationId: string; locale: string; text: string }): Promise { diff --git a/apps/even-client/test/reducer.test.ts b/apps/even-client/test/reducer.test.ts index 57091a3..1b2c4c6 100644 --- a/apps/even-client/test/reducer.test.ts +++ b/apps/even-client/test/reducer.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest'; import { SCHEMA_VERSION, type TurnResult } from '@hermeven/contracts'; import { pollDelay } from '../src/core/controller.ts'; +import { renderHud } from '../src/core/hud.ts'; import { initialState, reduce, type AppEvent, type AppState, type Effect } from '../src/core/reducer.ts'; const ID1 = '11111111-1111-4111-8111-111111111111'; @@ -369,3 +370,62 @@ describe('pairing, restore and conversations', () => { expect(step.effects).toEqual([{ type: 'discard_capture' }]); }); }); + +describe('choosing an agent', () => { + const AGENTS = [ + { id: 'default', name: 'Pepper' }, + { id: 'wendy', name: 'Wendy' }, + ]; + const WENDY_CONV = 'dddddddd-dddd-4ddd-8ddd-dddddddddddd'; + const readyWithAgents = () => + run(initialState, { type: 'init', paired: true, conversationId: CONV, captureMaxSeconds: 30, resumeRequestId: null, agents: AGENTS, agentId: null }).state; + const select: AppEvent = { type: 'agent_selected', agentId: 'wendy', conversationId: WENDY_CONV }; + + it('at Ready: the agent and its own conversation are swapped in under a new conversation epoch', () => { + const before = readyWithAgents(); + const { state, effects } = run(before, select); + expect(effects).toEqual([]); + expect(state.phase).toBe('ready'); + expect(state.agentId).toBe('wendy'); + expect(state.conversationId).toBe(WENDY_CONV); + expect(state.conversationEpoch).toBe(before.conversationEpoch + 1); + expect(state.generation).toBe(before.generation + 1); + expect(renderHud(state, 0).body).toBe('Wendy\n\nReady.'); + }); + + it('is ignored on every other screen: listening, in flight, an answer, an error, cancelled, unpaired', () => { + const base = readyWithAgents(); + const others: AppState[] = [ + run(base, { type: 'activate', freshId: ID1 }).state, + run(base, { type: 'submit_text', freshId: ID1, text: 'q' }).state, + run(base, { type: 'submit_text', freshId: ID1, text: 'q' }, { type: 'turn_update', generation: base.generation + 1, result: result(ID1), pages: ['a'] }).state, + run(base, { type: 'activate', freshId: ID1 }, { type: 'capture_failed', generation: base.generation + 1, reason: 'mic_refused' }).state, + run(base, { type: 'activate', freshId: ID1 }, { type: 'cancel' }).state, + { ...initialState, agents: AGENTS }, + ]; + expect(others.map((s) => s.phase)).toEqual(['listening', 'thinking', 'answer', 'error', 'cancelled', 'unpaired']); + for (const state of others) expect(reduce(state, select).state, state.phase).toBe(state); + }); + + it('an agent that is not offered, or the one already current, changes nothing', () => { + const base = readyWithAgents(); + expect(reduce(base, { type: 'agent_selected', agentId: 'natalie', conversationId: null }).state).toBe(base); + expect(reduce(base, { type: 'agent_selected', agentId: 'default', conversationId: null }).state).toBe(base); + }); + + it('a conversation created for the previous agent cannot land on the new one', () => { + const base = readyWithAgents(); + const creating = run(base, { type: 'new_conversation' }).state; + const moved = run(creating, { type: 'agent_selected', agentId: 'wendy', conversationId: null }).state; + const late = reduce(moved, { type: 'conversation_created', epoch: creating.conversationEpoch, conversationId: CONV }).state; + expect(late.conversationId).toBeNull(); + expect(late.creatingConversation).toBe(false); + }); + + it('with one agent, or none listed, no screen mentions an agent', () => { + for (const agents of [[], [AGENTS[0]!]]) { + const state = run(initialState, { type: 'init', paired: true, conversationId: CONV, captureMaxSeconds: 30, resumeRequestId: null, agents }).state; + expect(renderHud(state, 0)).toEqual({ body: 'Hermeven\n\nReady.', status: 'Tap: ask · Double-tap: exit' }); + } + }); +}); diff --git a/deploy/bridge.env.example b/deploy/bridge.env.example index 3f121d4..c572564 100644 --- a/deploy/bridge.env.example +++ b/deploy/bridge.env.example @@ -3,6 +3,14 @@ HERMES_BASE_URL=http://127.0.0.1:8642 HERMES_API_KEY=replace-with-the-hermes-api-server-key HERMES_PROFILE_LABEL=default +# Optional: more agents on the glasses (swipe at Ready to choose). Each is another profile of the +# same Hermes gateway and needs its OWN key: add API_SERVER_KEY to that profile's .env on the +# Hermes side, then repeat it here. See docs/bridge-api.md, "More than one agent". +# HERMEVEN_AGENT_NAME=Pepper +# HERMEVEN_AGENTS=wendy,cody +# HERMEVEN_AGENT_WENDY_API_KEY=replace-with-wendy-profile-api-server-key +# HERMEVEN_AGENT_CODY_API_KEY=replace-with-cody-profile-api-server-key + HERMEVEN_HOST=127.0.0.1 HERMEVEN_PORT=8787 # Caddy is in front, so the client address comes from its forwarded header. diff --git a/docs/bridge-api.md b/docs/bridge-api.md index 5cd1559..fb4983e 100644 --- a/docs/bridge-api.md +++ b/docs/bridge-api.md @@ -18,7 +18,8 @@ Every error has the shape: | `GET /v1/device` | Pairing status, limits, whether the agent is reachable and STT is configured. | 200 | | `POST /v1/device/renew` | Rotate the device token. The old token stops working at once. | 200 | | `DELETE /v1/device` | Revoke this device and close its conversation. | 200 | -| `POST /v1/conversations` | Start a new conversation; closes the device's previous one. | 201 | +| `GET /v1/agents` | The agents this device may talk to, default first: `{agents: [{id, name}]}`. Ids and display names only; no address, profile or key. Added after 0.1.x: an older bridge answers 404 `not_found`, which a client must treat as "one agent". | 200 | +| `POST /v1/conversations` | Start a new conversation. Optional `agent_id` (an id from `/v1/agents`; omitted = the default agent; anything else is 400 `invalid_request`). Closes the device's previous conversation **with that agent** only. | 201 | | `POST /v1/turns` | Create one turn (text or audio). | 202, or 200 for a duplicate | | `GET /v1/turns/{request_id}` | Current state and result. | 200 | | `POST /v1/turns/{request_id}/cancel` | Request cancellation. Idempotent. | 200 | @@ -26,6 +27,26 @@ Every error has the shape: There is no SSE endpoint. Streaming through the Even WebView is undocumented and untested, so polling is the supported path. +## More than one agent + +The bridge can be given further agents besides the default one. Each is another profile served by +the same Hermes gateway (`gateway.multiplex_profiles`), reached at `/p/` +with that profile's own `API_SERVER_KEY`; Hermes refuses the default profile's key there. + +``` +HERMEVEN_AGENT_NAME=Pepper # display name of the default agent (default: Agent) +HERMEVEN_AGENTS=wendy,cody # extra agent ids, in display order +HERMEVEN_AGENT_WENDY_API_KEY=... # required for each extra agent +HERMEVEN_AGENT_WENDY_PROFILE=wendy # optional; default: the id +HERMEVEN_AGENT_WENDY_NAME=Wendy # optional; default: the id, capitalised +``` + +The list is the owner's allow-list. A client names an agent only by id, only when creating a +conversation, and the id is checked against the list; it is never used to build an address. A +turn goes to the agent of its conversation. Each agent has its own conversation and its own +Hermes session, so nothing said to one is sent to another. `/v1/device` is unchanged, and its +`active_conversation_id` and `agent_reachable` describe the default agent. + ## Creating a turn Typed text (`Content-Type: application/json`): diff --git a/docs/contracts/2026-11-21-droplet-deployment-and-first-device-run.md b/docs/contracts/2026-11-21-droplet-deployment-and-first-device-run.md index 525f605..9f7b16c 100644 --- a/docs/contracts/2026-11-21-droplet-deployment-and-first-device-run.md +++ b/docs/contracts/2026-11-21-droplet-deployment-and-first-device-run.md @@ -112,6 +112,23 @@ F4 as revised (build 0.1.2): the countdown runs however the app was opened. It s leaves while recording, transcribing, waiting for the agent or for an approval, or while unpaired, and a touch on the phone page still holds it open for two minutes. +### G. Choosing an agent (from Dan's words on 2026-11-21) + +A build for trial. Per Dan's standing instruction, his keep/change/remove decisions follow the +device trial; nothing here is pre-accepted beyond what he is quoted as asking for. + +| # | Dan said | Criterion | +|---|---|---| +| G1 | "what I want to build next is the ability to chat with all my agents... wendy is a sub-agent of pepper and being able to summon her through the app would be ideal." | The app can talk to more than one agent through the one bridge. | +| G2 | "when pepper opens, and is inthe ready state, what if swiping could change the active agent? So pepper would show, but if we swipe, it would move between different available agents?" | At Ready a swipe moves to the next or previous agent; the app opens on the default agent and shows the current agent's name. | +| G3 | "when no name is stated, then it uses pepper/default." | With no choice made, questions go to the default agent exactly as before. | +| G4 | Asked whether to reopen on Pepper or on the last agent: "could we use the same 15 minute time out (I think that's what it is) that determines if it's a new session, or picks up from the last?" | Reopened within the conversation window (ten minutes; Dan was told it is ten, not fifteen), the app opens on the agent last talked to, in the same conversation; otherwise on the default. | +| G5 | On the agent list coming from the bridge's settings: "Yeah, sure. that's fine." | The list is configured on the bridge; the phone can only pick from it. | +| G6 | "Pepper, wendy and cody. yes. go for it." | The three agents for the first trial. Also Dan's go-ahead for giving the wendy and cody profiles an API key on the server. | +| G7 | (implementer's choices, not requested) | Each agent has its own conversation. A follow-up goes to the agent that answered. On an answer a swipe still turns the page. The agent's name is shown while listening, thinking and on the answer. With only one agent the screens are unchanged. | + +Not built: saying a name to route a question. Dan first preferred it, then proposed the swipe. + ## Out of scope for this contract Wake word ("Hey Pepper"), automatic end-of-speech detection, summoning other agents by name, diff --git a/docs/evidence/droplet/2026-11-21.md b/docs/evidence/droplet/2026-11-21.md index c6b35e9..0efa972 100644 --- a/docs/evidence/droplet/2026-11-21.md +++ b/docs/evidence/droplet/2026-11-21.md @@ -257,3 +257,38 @@ message by a few minutes, on the owner's instruction. `evenhub ls` at 23:21 UTC: 0.1.1; 0.1.0 retained, on no channel. The server was not changed. Build 0.1.2 has **not** been uploaded. + +## 23:48 UTC: build 0.1.2 uploaded + +Cody, Round 14: SHIP (trial designation SHIP FOR TRIAL) on +`15714bd848a7bf7230bb80d187de85af4b3fa66b`. Dan: "yes, upload 0.1.2". `evenhub upload` (id 155527, +99,892 bytes, SHA-256 `3781f3e8256f0efdba4155fbd5d0926a6726f14ca3ed89bc039d34b48a0f608b`, built from +that commit) and `evenhub promote 0.1.2 --to beta`. Dan has not reported a trial of 0.1.2. + +## 23:52 to 23:58 UTC: Hermes profiles surveyed; keys added for wendy and cody + +Read-only survey (Dan: "Yes, take a read-only survey"): + +| Found | Detail | +|---|---| +| Profiles | default, cody, jeanette, natalie, wendy, all with a running gateway | +| Gateways | `hermes-gateway.service` serves default, cody, natalie and wendy (`gateway.multiplex_profiles: true`); `hermes-gateway-jeanette.service` is separate and not on port 8642 | +| API | Hermes v0.23.1 source: named profiles are served at `/p//...` on the same port, each authorised by that profile's own `API_SERVER_KEY`, failing closed without one | +| Unauthenticated probes | `/p/wendy/health`, `/p/cody/health`, `/p/natalie/health`: 200. `/p/jeanette/health`, `/p/nosuch/health`: 404 | +| Keys before | Only the default profile had `API_SERVER_KEY` | + +Changes (Dan: "Pepper, wendy and cody. yes. go for it."): + +| Step | Result | +|---|---| +| `API_SERVER_KEY` (64 hex, generated on the server, never displayed) appended to `profiles/wendy/.env`; previous file kept as `.env.bak-hermeven-