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/<profile> 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 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-21 16:08:11 -08:00
co-authored by Claude Fable 5.2
parent 15714bd848
commit 9394c249ad
20 changed files with 1117 additions and 42 deletions
+60
View File
@@ -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' });
}
});
});