Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Expose app focus to paired devices and guard voice dispatch

leo2a6eb125e948
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 434f60aa7..3edeb0733 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -1313,6 +1313,7 @@ async function runForeground(session: AuthSession): Promise<void> {
}
let autonomousDeviceDirect: AutonomousDeviceDirect | undefined
let autonomousDeviceService: AutonomousDeviceService | undefined
+ let appVoiceFocus: { machineId: string; agentId: string; connId: string } | undefined
let backendRef: BackendSocket | undefined
let fullReconcile: (announceDevice?: boolean) => Promise<void> = async () => {}
@@ -2895,6 +2896,12 @@ async function runForeground(session: AuthSession): Promise<void> {
const localWsServer = attachLocalWsServer(hookServer, {
// The window and the dial are one desk: opening an agent in the app brings the dial to it, switching
// the dial's machine first when the app moved to another one.
+ onAppFocusState: (machineId, agentId, connId) => {
+ if (agentId === null) {
+ if (appVoiceFocus?.connId === connId) appVoiceFocus = undefined
+ } else appVoiceFocus = { machineId, agentId, connId }
+ autonomousDeviceService?.appFocus(machineId, agentId, connId)
+ },
onAppFocus: (machineId, agentId) => { void cableRef?.followApp(machineId, agentId) },
// Agents the window has a tile for. A finished turn on one of these is
// already in front of the person, so the dial updates its tile in silence
@@ -4201,6 +4208,7 @@ async function runForeground(session: AuthSession): Promise<void> {
fullText: id => mirror.lastFullText(registry.byAgent(id)?.sessionId ?? id),
emit: frame => backend.emitAutonomousDeviceEvent(frame),
})
+ if (appVoiceFocus) autonomousDeviceService.appFocus(appVoiceFocus.machineId, appVoiceFocus.agentId, appVoiceFocus.connId)
backend.setAutonomousDeviceService(autonomousDeviceService)
autonomousDeviceDirect = new AutonomousDeviceDirect({
machineId: backend.machineId, label: hostname(),
diff --git a/cli/src/lib/autonomous-device/service.spec.ts b/cli/src/lib/autonomous-device/service.spec.ts
index b6c983435..0be094807 100644
--- a/cli/src/lib/autonomous-device/service.spec.ts
+++ b/cli/src/lib/autonomous-device/service.spec.ts
@@ -132,3 +132,74 @@ describe('Autonomous device turn.summary carries the complete answer', () => {
expect(f.events.find(e => e.kind === 'turn.summary')!.payload).not.toHaveProperty('fullText')
})
})
+
+describe('Autonomous device app focus', () => {
+ it('exposes revisions, remote focus, owner-aware clear and server identity', async () => {
+ const f = fixture()
+ const read = () => f.service.request('device', { type: 'focus.get', requestId: randomUUID() })
+ const empty = await read()
+ expect(empty.focus).toBeNull()
+ f.service.appFocus('machine', 'agent', 'window-a')
+ const first = await read()
+ expect(first.focus).toEqual({ machineId: 'machine', agentId: 'agent', name: 'Project' })
+ expect(first.focusRevision).not.toBe(empty.focusRevision)
+ f.service.appFocus('remote', 'remote-agent', 'window-b')
+ f.service.appFocus('machine', null, 'window-a')
+ expect((await read()).focus).toEqual({ machineId: 'remote', agentId: 'remote-agent' })
+ f.service.appFocus('remote', null, 'window-b')
+ expect((await read()).focus).toBeNull()
+ expect(f.events.filter(e => e.kind === 'focus.changed')).toHaveLength(3)
+ expect(fixture().service.focusSnapshot().focusRevision).not.toBe(empty.focusRevision)
+ })
+ it('keeps the revision stable for reannounced focus while transferring ownership', () => {
+ const f = fixture()
+ f.service.appFocus('machine', 'agent', 'old-window')
+ const before = f.service.focusSnapshot()
+ f.service.appFocus('machine', 'agent', 'old-window')
+ f.service.appFocus('machine', 'agent', 'new-window')
+ f.service.appFocus('machine', null, 'old-window')
+ expect(f.service.focusSnapshot()).toEqual(before)
+ expect(f.events.filter(e => e.kind === 'focus.changed')).toHaveLength(1)
+ f.service.appFocus('machine', null, 'new-window')
+ expect(f.service.focusSnapshot().focus).toBeNull()
+ expect(f.service.focusSnapshot().focusRevision).not.toBe(before.focusRevision)
+ })
+ it('guards sends before reservation, preserves duplicates, and rejects focus ABA', async () => {
+ const f = fixture()
+ f.service.appFocus('machine', 'agent', 'window')
+ const { focusRevision } = f.service.focusSnapshot()
+ expect((await f.service.request('device', f.send({ focusRevision }))).status).toBe('accepted')
+ f.service.appFocus('machine', null, 'window')
+ f.service.appFocus('machine', 'agent', 'window')
+ expect((await f.service.request('device', f.send({ focusRevision }))).status).toBe('duplicate')
+ expect((await f.service.request('device', f.send({ focusRevision, idempotencyKey: 'new' }))).error).toMatchObject({ code: 'FOCUS_CHANGED' })
+ expect(f.service.receipt('device', 'new')).toBeNull()
+ expect(f.submit).toHaveBeenCalledTimes(1)
+ expect((await f.service.request('device', f.send({ idempotencyKey: 'legacy' }))).status).toBe('accepted')
+ })
+ it('checks the target as well as the revision and guards question answers', async () => {
+ const f = fixture()
+ f.service.appFocus('remote', 'other', 'window')
+ const { focusRevision } = f.service.focusSnapshot()
+ expect((await f.service.request('device', f.send({ focusRevision }))).error).toMatchObject({ code: 'FOCUS_CHANGED' })
+ f.service.commander({ type: 'commander_question', agentId: 'agent', payload: { requestId: 'q', questions: [] } })
+ expect((await f.service.request('device', { type: 'question.answer', requestId: randomUUID(), machineId: 'machine', agentId: 'agent',
+ idempotencyKey: 'answer', questionRequestId: 'q', answers: { choice: 'yes' }, focusRevision })).error).toMatchObject({ code: 'FOCUS_CHANGED' })
+ expect(f.answer).not.toHaveBeenCalled()
+ expect(f.service.receipt('device', 'answer')).toBeNull()
+ })
+ it('invalidates a deleted agent before dispatch', async () => {
+ let agents = [{ agentId: 'agent', name: 'Project', engine: 'claude', state: 'idle' }]
+ const submit = vi.fn()
+ const service = new AutonomousDeviceService({ machineId: 'machine', agents: () => agents, submit,
+ cancelDelivery: () => true, stop: async () => true, answer: async () => true, recent: () => [] })
+ service.appFocus('machine', 'agent', 'window')
+ const { focusRevision } = service.focusSnapshot()
+ agents = []
+ expect((await service.request('device', { type: 'turn.send', requestId: randomUUID(), machineId: 'machine', agentId: 'agent',
+ text: 'hello', idempotencyKey: 'deleted', focusRevision })).error).toMatchObject({ code: 'FOCUS_CHANGED' })
+ expect(service.focusSnapshot()).toMatchObject({ focus: null })
+ expect(service.focusSnapshot().focusRevision).not.toBe(focusRevision)
+ expect(submit).not.toHaveBeenCalled()
+ })
+})
diff --git a/cli/src/lib/autonomous-device/service.ts b/cli/src/lib/autonomous-device/service.ts
index 9ced63888..4cd947d7e 100644
--- a/cli/src/lib/autonomous-device/service.ts
+++ b/cli/src/lib/autonomous-device/service.ts
@@ -29,7 +29,7 @@ export interface AutonomousDeviceServiceOptions {
emit?: (frame: AutonomousDeviceFrame) => void
}
interface Entry { deviceId: string; digest: string; receipt: AutonomousDeviceReceipt }
-const CAPABILITIES = ['agents.list', 'turn.send', 'turn.stop', 'status', 'recap', 'question.answer', 'receipt.get'] as const
+const CAPABILITIES = ['focus.get', 'agents.list', 'turn.send', 'turn.stop', 'status', 'recap', 'question.answer', 'receipt.get'] as const
export const AUTONOMOUS_DEVICE_CAPABILITIES: string[] = [...CAPABILITIES]
const MUTATIONS = new Set(['turn.send', 'turn.stop', 'question.answer'])
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
@@ -54,6 +54,33 @@ export class AutonomousDeviceService {
private readonly questions = new Map<string, { requestId: string; questions: unknown }>()
private events: AutonomousDeviceFrame[] = []
private sequence = 0
+ private focusOwner: string | undefined
+ private focused: { machineId: string; agentId: string } | null = null
+ private focusCounter = 0
+ /** Only explicit app focus updates own this state; disconnects cannot clear a newer owner. */
+ appFocus(machineId: string, agentId: string | null, connId: string): void {
+ if (agentId === null && this.focusOwner !== connId) return
+ if (machineId === this.options.machineId && agentId !== null && !this.options.agents().some(a => a.agentId === agentId)) agentId = null
+ this.focusOwner = agentId === null ? undefined : connId
+ if (agentId === null ? this.focused === null : this.focused?.machineId === machineId && this.focused?.agentId === agentId) return
+ this.focused = agentId === null ? null : { machineId, agentId }
+ this.focusCounter++
+ this.event('focus.changed', undefined, this.focusSnapshot())
+ }
+ focusSnapshot(): { focus: { machineId: string; agentId: string; name?: string } | null; focusRevision: string } {
+ const local = this.focused?.machineId === this.options.machineId
+ const agent = local ? this.options.agents().find(a => a.agentId === this.focused?.agentId) : undefined
+ if (local && !agent) {
+ this.focused = null
+ this.focusOwner = undefined
+ this.focusCounter++
+ const snapshot = { focus: null, focusRevision: `${this.serverInstanceId}:${this.focusCounter}` }
+ this.event('focus.changed', undefined, snapshot)
+ return snapshot
+ }
+ return { focus: this.focused ? { ...this.focused, ...(agent ? { name: agent.name } : {}) } : null,
+ focusRevision: `${this.serverInstanceId}:${this.focusCounter}` }
+ }
constructor(private readonly options: AutonomousDeviceServiceOptions) {
this.serverInstanceId = options.serverInstanceId ?? randomUUID()
this.now = options.now ?? Date.now
@@ -162,13 +189,15 @@ export class AutonomousDeviceService {
try {
if (!UUID.test(String(req.requestId))) fail('INVALID_REQUEST', 'requestId must be a UUIDv4')
if (!AUTONOMOUS_DEVICE_CAPABILITIES.includes(type)) fail('UNSUPPORTED_CAPABILITY', 'Operation is not supported')
- const allowed = ['type', 'requestId', ...(type === 'agents.list' ? [] : type === 'receipt.get' ? ['idempotencyKey'] : ['machineId', 'agentId']),
- ...(MUTATIONS.has(type) ? ['idempotencyKey'] : []), ...(type === 'turn.send' ? ['text'] : type === 'question.answer' ? ['questionRequestId', 'answers'] : type === 'recap' ? ['n'] : [])]
+ const allowed = ['type', 'requestId', ...(['agents.list', 'focus.get'].includes(type) ? [] : type === 'receipt.get' ? ['idempotencyKey'] : ['machineId', 'agentId']),
+ ...(MUTATIONS.has(type) ? ['idempotencyKey'] : []), ...(type === 'turn.send' ? ['text', 'focusRevision'] : type === 'question.answer' ? ['questionRequestId', 'answers', 'focusRevision'] : type === 'recap' ? ['n'] : [])]
if (Object.keys(req).some(k => !allowed.includes(k))) fail('INVALID_REQUEST', 'Unknown request field')
if (type === 'receipt.get') {
if (!KEY.test(String(req.idempotencyKey ?? ''))) fail('INVALID_REQUEST', 'Invalid idempotencyKey')
return response({ receipt: this.receipt(deviceId, String(req.idempotencyKey)) })
}
+ if (type === 'focus.get') return response(this.focusSnapshot())
+ if ('focusRevision' in req && (typeof req.focusRevision !== 'string' || !req.focusRevision)) fail('INVALID_REQUEST', 'focusRevision must be a nonempty string')
if (type === 'agents.list') return response({ machineId: this.options.machineId, agents: this.options.agents().map(a => ({ ...a, machineId: this.options.machineId })) })
if (typeof req.agentId !== 'string' || !req.agentId || typeof req.machineId !== 'string') fail('MISSING_TARGET', 'machineId and agentId are required')
if (req.machineId !== this.options.machineId) fail('MACHINE_MISMATCH', 'Only the paired machine is available')
@@ -186,6 +215,12 @@ export class AutonomousDeviceService {
if (previous.digest !== digest) fail('IDEMPOTENCY_CONFLICT', 'Key already belongs to a different operation or payload')
return response({ status: 'duplicate', receipt: structuredClone(previous.receipt) })
}
+ if ('focusRevision' in req) {
+ const snapshot = this.focusSnapshot()
+ if (req.focusRevision !== snapshot.focusRevision || snapshot.focus?.machineId !== req.machineId || snapshot.focus?.agentId !== agentId) {
+ fail('FOCUS_CHANGED', 'App focus changed before dispatch; no operation was reserved')
+ }
+ }
const agent = this.options.agents().find(a => a.agentId === agentId)
if (!agent) fail('AGENT_NOT_FOUND', 'Agent is not available on the paired machine')
if (type === 'status') return response({ machineId: this.options.machineId, agentId, state: agent.state, openQuestion: this.questions.get(agentId) ?? null })
diff --git a/cli/src/localWsServer.spec.ts b/cli/src/localWsServer.spec.ts
index 963daa998..a2538b19c 100644
--- a/cli/src/localWsServer.spec.ts
+++ b/cli/src/localWsServer.spec.ts
@@ -171,6 +171,34 @@ describe('local CLI WebSocket', () => {
ws.close()
})
+ it('reports only explicit voice focus and clears by originating connection', async () => {
+ const backend = new FakeBackend()
+ const states: Array<{ machine: string; agent: string | null; conn: string }> = []
+ server = http.createServer((_req, res) => { res.statusCode = 404; res.end() })
+ local = attachLocalWsServer(server, {
+ machineId, backend,
+ onAppFocusState: (machine, agent, conn) => states.push({ machine, agent, conn }),
+ })
+ await new Promise<void>(resolve => server!.listen(0, '127.0.0.1', resolve))
+ const ws = new WebSocket(`ws://127.0.0.1:${(server.address() as AddressInfo).port}/api/local-ws`)
+ await onceOpen(ws)
+ const connected = onceMessage(ws)
+ ws.send(JSON.stringify({ type: 'machine_select', payload: { machineId, localProtocolVersion: 1 } }))
+ await connected
+ ws.send(JSON.stringify({ type: 'terminal_open', payload: { agentId: 'background' } }))
+ ws.send(JSON.stringify({ type: 'app_focus', payload: { agentId: 'focused' } }))
+ ws.send(JSON.stringify({ type: 'terminal_open', payload: { agentId: 'another-background' } }))
+ await vi.waitFor(() => expect(states).toHaveLength(1))
+ expect(states[0]).toMatchObject({ machine: machineId, agent: 'focused' })
+ ws.send(JSON.stringify({ type: 'app_focus', payload: { agentId: null } }))
+ await vi.waitFor(() => expect(states).toHaveLength(2))
+ expect(states[1]).toEqual({ ...states[0], agent: null })
+ expect(backend.frames.map(frame => frame.type)).toEqual(['terminal_open', 'terminal_open'])
+ ws.close()
+ await vi.waitFor(() => expect(states).toHaveLength(3))
+ expect(states[2]).toEqual(states[1])
+ })
+
it('carries the window\'s answer about a spoken task, and keeps it off the wire', async () => {
const backend = new FakeBackend()
const replies: Array<{ voiceId: string; reply: unknown }> = []
diff --git a/cli/src/localWsServer.ts b/cli/src/localWsServer.ts
index 1e73325ac..e05853d57 100644
--- a/cli/src/localWsServer.ts
+++ b/cli/src/localWsServer.ts
@@ -40,6 +40,8 @@ export interface LocalWsServerOptions {
autonomousEnv?: string
/** The desktop app opened an agent's terminal — which agent, and on which machine. Lets the dial follow
* the window, so the two screens stay one desk. */
+ /** Explicit app focus, including clear/disconnect, for voice routing independent of the dial. */
+ onAppFocusState?: (machineId: string, agentId: string | null, connId: string) => void
onAppFocus?: (machineId: string, agentId: string) => void
/** Every agent the window currently has a tile for, across all its machines. */
onAppPanes?: (agentIds: string[]) => void
@@ -356,24 +358,20 @@ export function attachLocalWsServer(server: http.Server, options: LocalWsServerO
return
}
}
- if (!isBinary && options.onAppFocus && boundMachineId) {
+ if (!isBinary && boundMachineId && ws.readyState === WebSocket.OPEN) {
const moved = jsonFrame(raw)
const agentId = (moved?.payload as Record<string, unknown> | undefined)?.agentId
- if (typeof agentId === 'string' && agentId) {
- // `app_focus` is the window SAYING where it is looking. `terminal_open` is it being
- // inferred from a side effect, which is all there was when a window could only show one
- // terminal: every move opened a stream, so opening one meant it had moved.
- //
- // A pane grid breaks that equivalence. Clicking a tile that already holds a live session
- // opens nothing at all, so the dial never heard about it and stayed on the agent the last
- // rail click had opened. Both are still read: an older app build only sends the second.
- if (moved?.type === 'app_focus') {
- options.onAppFocus(boundMachineId, agentId)
- // Consumed here. It describes a hand at THIS desk and the machine has no use for it —
- // forwarding it would put an unknown frame type on the wire for every pane click.
- return
+ if (moved?.type === 'app_focus') {
+ if (agentId === null || (typeof agentId === 'string' && agentId)) {
+ options.onAppFocusState?.(boundMachineId, agentId, connId)
+ if (agentId) options.onAppFocus?.(boundMachineId, agentId)
}
- if (moved?.type === 'terminal_open') options.onAppFocus(boundMachineId, agentId)
+ // Focus is local desk state and must never be forwarded to a remote machine.
+ return
+ }
+ // Preserve the old dial fallback; terminal streams never establish voice focus.
+ if (moved?.type === 'terminal_open' && typeof agentId === 'string' && agentId) {
+ options.onAppFocus?.(boundMachineId, agentId)
}
}
@@ -414,6 +412,7 @@ export function attachLocalWsServer(server: http.Server, options: LocalWsServerO
const cleanup = (): void => {
clearInterval(heartbeat)
+ if (boundMachineId) options.onAppFocusState?.(boundMachineId, null, connId)
// A window that went away has no tiles open. Left standing, the roster
// would keep silencing the dial for agents nobody can see any more —
// exactly backwards, and permanently.
diff --git a/docs/autonomous-device-integration.md b/docs/autonomous-device-integration.md
index 5469b296c..efcc444d5 100644
--- a/docs/autonomous-device-integration.md
+++ b/docs/autonomous-device-integration.md
@@ -125,19 +125,37 @@ a duplicate may return any retained receipt state. Supported operations:
| Operation | Additional request fields | Success fields |
|---|---|---|
+| `focus.get` | none | `focus:null\|{machineId,agentId,name?},focusRevision` |
| `agents.list` | none | `machineId,agents:[{machineId,agentId,name,engine,state}]` |
| `status` | `machineId,agentId` | `machineId,agentId,state,openQuestion:null\|{requestId,questions}` |
| `recap` | `machineId,agentId,n?` (default 3, integer 1–5) | `machineId,agentId,turns:[{kind,text,recap?,fullText?}]` |
-| `turn.send` | `machineId,agentId,idempotencyKey,text` | `status,receipt` |
+| `turn.send` | `machineId,agentId,idempotencyKey,text,focusRevision?` | `status,receipt` |
| `turn.stop` | `machineId,agentId,idempotencyKey` | `status,receipt` |
-| `question.answer` | `machineId,agentId,idempotencyKey,questionRequestId,answers` | `status,receipt` |
+| `question.answer` | `machineId,agentId,idempotencyKey,questionRequestId,answers,focusRevision?` | `status,receipt` |
| `receipt.get` | `idempotencyKey` | `receipt:null\|Receipt` |
`idempotencyKey` matches `[A-Za-z0-9_-]{1,64}`. Prompt must be nonblank and ≤16 KiB UTF-8;
it is never truncated. Answers is a nonempty object mapping question keys to string answers.
Question ID must still be open. Question answering cannot approve tool permissions.
Agent state currently derives `running`/`idle` from the local registry/turn tracker.
-There is no CLI selection operation: OS retains a validated explicit target.
+There is no CLI selection operation: the desktop app supplies the voice target through explicit
+local `app_focus {agentId}` frames. `app_focus {agentId:null}` clears the owning connection's focus;
+disconnecting that connection also clears it, but an older connection cannot clear a newer owner.
+Opening terminal streams does not establish voice focus. Before the first app focus, focus is null.
+`focus.get` is advertised in hello capabilities and requires only a request ID. `focus.changed`
+events carry the same `{focus,focusRevision}` snapshot in their payload. Revisions are opaque strings
+unique across server restarts; every change of focus changes the revision, including focus A→B→A. Reannouncing the same target
+keeps its revision stable while transferring ownership to the announcing connection.
+A removed local agent clears focus when the snapshot is read. Remote app focus is reported with its
+remote machine ID; this local-only device facade does not substitute a local target or relay dispatch.
+OS can display the snapshot on Monitor Pairing and poll it to recover missed events.
+
+Voice clients pass the snapshot's `focusRevision` with explicit `machineId,agentId` on `turn.send`
+and `question.answer`. After checking retained duplicates, the service synchronously verifies both
+revision and target before reserving or dispatching new work. Mismatch returns `FOCUS_CHANGED`
+without a receipt: that request did not dispatch. A duplicate keeps its original receipt even if
+focus moved. Requests without `focusRevision` retain legacy explicit-target behavior. `turn.stop`
+does not accept the field, so stopping an existing turn remains tied to its original target.
Receipt:
@@ -203,7 +221,7 @@ delivered/started/completed means adopt; rejected means report; unknown/null mea
before resending. Never automatically replay mutations on reconnect.
Application errors include `INVALID_REQUEST`, `UNSUPPORTED_CAPABILITY`, `MISSING_TARGET`,
-`MACHINE_MISMATCH`, `AGENT_NOT_FOUND`, `PAYLOAD_TOO_LARGE`, `QUESTION_STALE`,
+`MACHINE_MISMATCH`, `AGENT_NOT_FOUND`, `FOCUS_CHANGED`, `PAYLOAD_TOO_LARGE`, `QUESTION_STALE`,
`IDEMPOTENCY_CONFLICT`, `BACKPRESSURE`, `RATE_LIMITED`, `REVOKED`, `INTERNAL`.
A per-relay-connection token bucket permits burst 20, refilling one request/second, with at most four async
requests in flight; a new relay connection starts a new quota. Excess returns an error result.
diff --git a/docs/vi/autonomous-device-integration_vi.md b/docs/vi/autonomous-device-integration_vi.md
index e66f08b20..fb0c6b1c6 100644
--- a/docs/vi/autonomous-device-integration_vi.md
+++ b/docs/vi/autonomous-device-integration_vi.md
@@ -46,6 +46,27 @@ crypto, không kết nối backend. Request agents.list/status/recap/turn.send/t
receipt.get giữ target rõ và receipt/dedupe. Không replay mutation khi mất kết nối; unknown không
có nghĩa chưa gửi. Cache512/ring500 và schema đầy đủ ở [bản EN](../autonomous-device-integration.md).
+## Focus của app cho voice
+
+CLI quảng bá capability `focus.get`; request `{type:"focus.get",requestId}` trả
+`{type:"focus.get_result",requestId,focus:null|{machineId,agentId,name?},focusRevision}`.
+Event `focus.changed` có payload `{focus,focusRevision}` cùng schema. Monitor Pairing hiển thị
+snapshot này; OS có thể poll để phục hồi khi bỏ lỡ event.
+
+Nguồn focus là frame local tường minh `app_focus {agentId}` từ Desktop, không phải `terminal_open`.
+Ban đầu focus là null. `app_focus {agentId:null}` hoặc đóng socket đang sở hữu focus sẽ xóa focus;
+socket cũ không được xóa focus của socket mới. Mỗi thay đổi focus đổi revision, kể cả A→B→A; thông báo lại cùng target giữ nguyên revision
+nhưng chuyển quyền sở hữu sang socket thông báo;
+revision là chuỗi opaque có server instance ID nên khác sau restart. Khi đọc snapshot, agent local
+đã bị xóa làm focus thành null và đổi revision. Focus máy remote giữ đúng machine ID remote;
+facade device chỉ hỗ trợ máy đã pair, không thay bằng agent local hoặc tự relay task.
+
+`turn.send` và `question.answer` nhận `focusRevision` tùy chọn bên cạnh target ID tường minh.
+Sau bước kiểm tra receipt trùng, service kiểm tra đồng bộ revision và target trước khi reserve/gửi.
+Sai revision hoặc target trả `FOCUS_CHANGED` không receipt: request đó chưa dispatch. Request trùng
+đã reserve vẫn trả receipt cũ dù focus đổi. Client cũ không truyền revision vẫn dùng target tường minh
+như trước. `turn.stop` không nhận trường này, tiếp tục nhắm target của lượt đang chạy.
+
`turn.summary` và mỗi phần tử `recap.turns[]` mang ba mức của cùng một câu trả lời; bên tiêu thụ nên
ưu tiên `turns[].fullText`, rồi `turn.summary.fullText`, rồi `text`: