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
+53 -1
View File
@@ -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<Phase> = new Set(['ready', 'answer', 'error', 'cancelled']);
const IN_FLIGHT: ReadonlySet<Phase> = 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 {