@xenosystem/agent-interface-client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,523 @@
1
+ import { AgentHostProtocolError, XENO_AGENT_HOST_MIN_PROTOCOL_VERSION, XENO_AGENT_HOST_PROTOCOL_VERSION, assertCompatibleHandshake, isAgentHostHandshake, isAgentProviderListResult, isAgentRuntimeEventListResult, isAgentTurnCancelResult, isAgentTurnStartResult, } from '@xenosystem/agent-interface-contract';
2
+ export class AgentHostClient {
3
+ transport;
4
+ identity;
5
+ supportedProtocol;
6
+ handshake = null;
7
+ constructor(options) {
8
+ this.transport = options.transport;
9
+ this.identity = { ...options.identity };
10
+ this.supportedProtocol = options.supportedProtocol
11
+ ? { ...options.supportedProtocol }
12
+ : {
13
+ min: XENO_AGENT_HOST_MIN_PROTOCOL_VERSION,
14
+ max: XENO_AGENT_HOST_PROTOCOL_VERSION,
15
+ };
16
+ }
17
+ get surface() {
18
+ return this.identity.surface;
19
+ }
20
+ get instanceId() {
21
+ return this.identity.instanceId;
22
+ }
23
+ /**
24
+ * A copy of who this client is — for building an `AgentHostCommandContext`.
25
+ *
26
+ * Exposed so a bridge can mint the command itself rather than making every
27
+ * surface carry an identity it does not otherwise need. A copy, because a
28
+ * caller that could mutate this would be rewriting who it is between calls.
29
+ */
30
+ get clientIdentity() {
31
+ return { ...this.identity };
32
+ }
33
+ get connection() {
34
+ return this.handshake ? structuredClone(this.handshake) : null;
35
+ }
36
+ async connect() {
37
+ const response = await this.transport.request('host.handshake', {
38
+ identity: { ...this.identity },
39
+ supportedProtocol: { ...this.supportedProtocol },
40
+ });
41
+ if (!isAgentHostHandshake(response)) {
42
+ throw new AgentHostProtocolError('invalid_handshake', 'Agent host returned an invalid handshake.');
43
+ }
44
+ assertCompatibleHandshake(response, this.identity, this.supportedProtocol);
45
+ this.handshake = structuredClone(response);
46
+ return structuredClone(response);
47
+ }
48
+ async listProviders(options = {}) {
49
+ this.requireConnection();
50
+ const response = await this.transport.request('providers.list', {
51
+ ...(options.includeUnavailable === undefined
52
+ ? {}
53
+ : { includeUnavailable: options.includeUnavailable }),
54
+ });
55
+ if (!isAgentProviderListResult(response)) {
56
+ throw new AgentHostProtocolError('invalid_response', 'Agent host returned an invalid provider catalog.');
57
+ }
58
+ return structuredClone(response);
59
+ }
60
+ async refreshProviders(options = {}) {
61
+ this.requireConnection();
62
+ const response = await this.transport.request('providers.refresh', {
63
+ ...(options.includeUnavailable === undefined
64
+ ? {}
65
+ : { includeUnavailable: options.includeUnavailable }),
66
+ });
67
+ if (!isAgentProviderListResult(response)) {
68
+ throw new AgentHostProtocolError('invalid_response', 'Agent host returned an invalid refreshed provider catalog.');
69
+ }
70
+ return structuredClone(response);
71
+ }
72
+ async listRuntimeEvents(request) {
73
+ this.requireConnection();
74
+ const response = await this.transport.request('runtime.events.list', structuredClone(request));
75
+ if (!isAgentRuntimeEventListResult(response)) {
76
+ throw new AgentHostProtocolError('invalid_response', 'Agent host returned an invalid runtime-event page.');
77
+ }
78
+ return structuredClone(response);
79
+ }
80
+ /**
81
+ * Delivers a correction to a turn that is ALREADY RUNNING.
82
+ *
83
+ * ⚠️ `delivered` means the agent has it, never that the agent has stopped.
84
+ * Measured against real Claude Code: a correction lands at the agent's next
85
+ * decision point, not inside the tool call already in flight. `cancelTurn` is
86
+ * the mechanism for stop; this is for redirect.
87
+ *
88
+ * An adapter that cannot steer refuses by name (`steer_unsupported`) rather
89
+ * than silently accepting — a user who believes they corrected an agent that
90
+ * never heard them is the worst outcome here.
91
+ */
92
+ async steerTurn(request, options = {}) {
93
+ this.requireConnection();
94
+ const response = await this.transport.request('turn.steer', {
95
+ ...structuredClone(request),
96
+ command: this.createCommandContext(options, `turn:steer:${request.conversationId}:${request.requestId}`),
97
+ });
98
+ return response;
99
+ }
100
+ /**
101
+ * Holds an instruction for a running turn without requiring the agent to
102
+ * accept it mid-flight. Host-owned, so it works at every structure tier —
103
+ * unlike steering, which needs a protocol the agent listens on.
104
+ */
105
+ async queueTurnInstruction(request, options = {}) {
106
+ this.requireConnection();
107
+ const response = await this.transport.request('turn.queue', {
108
+ ...structuredClone(request),
109
+ command: this.createCommandContext(options,
110
+ // The queue is per CONVERSATION, not per turn — an instruction outlives
111
+ // the turn that was running when it was written.
112
+ `turn:queue:${request.conversationId}`),
113
+ });
114
+ return response;
115
+ }
116
+ /**
117
+ * Messages a run is not being told yet — coordination §6 `hold`.
118
+ *
119
+ * Plain read, no command context: listing changes nothing.
120
+ */
121
+ async listHeldMessages(request) {
122
+ this.requireConnection();
123
+ return structuredClone(await this.transport.request('coordination.held.list', structuredClone(request)));
124
+ }
125
+ /**
126
+ * A human approves one held message.
127
+ *
128
+ * 🔴 A wrapper is REQUIRED, not a convenience: the request carries a
129
+ * `command: AgentHostCommandContext`, which the host owns. Without one, a
130
+ * surface approving a message would have to forge the command id, the
131
+ * idempotency key and the client identity — and approving another agent's
132
+ * message is exactly the act that should be attributable.
133
+ */
134
+ async releaseHeldMessage(request, options = {}) {
135
+ this.requireConnection();
136
+ return structuredClone(await this.transport.request('coordination.held.release', {
137
+ ...structuredClone(request),
138
+ command: this.createCommandContext(options,
139
+ // Keyed by the MESSAGE: approving the same one twice is one approval,
140
+ // and approving a different one is a different act.
141
+ `coordination:held:release:${request.runId}:${request.messageId}`),
142
+ }));
143
+ }
144
+ /**
145
+ * Pins or clears a run's inbound-message policy — §6's override.
146
+ *
147
+ * `policy: null` returns the run to the derived default; it is NOT the same as
148
+ * `'accept'`, which pins the permissive answer.
149
+ */
150
+ async setInboundPolicy(request, options = {}) {
151
+ this.requireConnection();
152
+ return structuredClone(await this.transport.request('coordination.policy.set', {
153
+ ...structuredClone(request),
154
+ command: this.createCommandContext(options,
155
+ // Keyed by the run AND the value: pinning `hold` twice is one act, but
156
+ // changing it to `refuse` is a different decision and must not be
157
+ // collapsed into the first by a run-only key.
158
+ `coordination:policy:set:${request.runId}:${request.policy ?? 'derived'}`),
159
+ }));
160
+ }
161
+ /**
162
+ * What is waiting to run for this conversation.
163
+ *
164
+ * 🔴 A surface that can ENQUEUE and cannot LIST has given the user a
165
+ * write with no read: an instruction disappears into the host and the only
166
+ * evidence it exists is that it eventually runs. Both halves of the queue
167
+ * were implemented in the host and forwarded by the transport; only the
168
+ * enqueue had a client wrapper, so no surface could show a queue at all.
169
+ *
170
+ * Takes no command context because it changes nothing — see `dropQueued`
171
+ * below, which does.
172
+ */
173
+ async listQueuedInstructions(request) {
174
+ this.requireConnection();
175
+ return structuredClone(await this.transport.request('turn.queue.list', structuredClone(request)));
176
+ }
177
+ /**
178
+ * Removes a queued instruction, or clears the queue when none is named.
179
+ *
180
+ * 🔴 This wrapper is REQUIRED, not a convenience. The request carries a
181
+ * `command: AgentHostCommandContext`, which is host-owned — a caller must
182
+ * never mint one. Without a wrapper, a surface wanting to drop an
183
+ * instruction had to forge the command id, the idempotency key and the
184
+ * client identity itself, which is exactly the fact-forging the context
185
+ * exists to prevent.
186
+ */
187
+ async dropQueuedInstruction(request, options = {}) {
188
+ this.requireConnection();
189
+ return structuredClone(await this.transport.request('turn.queue.drop', {
190
+ ...structuredClone(request),
191
+ command: this.createCommandContext(options,
192
+ // Keyed per instruction, falling back to the conversation when the
193
+ // whole queue is cleared: a retried "clear everything" must not be
194
+ // mistaken for a retried "drop this one".
195
+ request.instructionId
196
+ ? `turn:queue:drop:${request.conversationId}:${request.instructionId}`
197
+ : `turn:queue:clear:${request.conversationId}`),
198
+ }));
199
+ }
200
+ /**
201
+ * Re-issues a turn that process death interrupted.
202
+ *
203
+ * Reported as `restarted`, never `resumed` — the request runs again rather
204
+ * than continuing from where it stopped.
205
+ */
206
+ async resumeTurn(request, options = {}) {
207
+ this.requireConnection();
208
+ const response = await this.transport.request('turn.resume', {
209
+ ...structuredClone(request),
210
+ command: this.createCommandContext(options, `turn:resume:${request.conversationId}:${request.requestId}`),
211
+ });
212
+ return response;
213
+ }
214
+ /**
215
+ * The permission rules the user chose to remember. Surfaced so they can be
216
+ * seen and revoked — they persist and accumulate, and a rule that cannot be
217
+ * taken back is a one-way door.
218
+ */
219
+ async listPermissionRules() {
220
+ this.requireConnection();
221
+ const response = await this.transport.request('permissions.rules.list', {});
222
+ return response;
223
+ }
224
+ async revokePermissionRule(ruleId) {
225
+ this.requireConnection();
226
+ const response = await this.transport.request('permissions.rules.revoke', { ruleId });
227
+ return response;
228
+ }
229
+ async loadWorkspaces() {
230
+ this.requireConnection();
231
+ return structuredClone(await this.transport.request('state.workspaces.load', {}));
232
+ }
233
+ async saveWorkspaces(workspaces) {
234
+ this.requireConnection();
235
+ return structuredClone(await this.transport.request('state.workspaces.save', {
236
+ workspaces: structuredClone(workspaces),
237
+ }));
238
+ }
239
+ async loadConversations() {
240
+ this.requireConnection();
241
+ return structuredClone(await this.transport.request('state.conversations.load', {}));
242
+ }
243
+ async saveConversation(conversation) {
244
+ this.requireConnection();
245
+ return structuredClone(await this.transport.request('state.conversations.save', {
246
+ conversation: structuredClone(conversation),
247
+ }));
248
+ }
249
+ async deleteConversation(conversationId) {
250
+ this.requireConnection();
251
+ return structuredClone(await this.transport.request('state.conversations.delete', { conversationId }));
252
+ }
253
+ async listWorkspaceDirectory(request) {
254
+ this.requireConnection();
255
+ return structuredClone(await this.transport.request('workspace.directory.list', {
256
+ ...structuredClone(request),
257
+ client: { ...this.identity },
258
+ }));
259
+ }
260
+ async readWorkspaceFile(request) {
261
+ this.requireConnection();
262
+ return structuredClone(await this.transport.request('workspace.file.read', {
263
+ ...structuredClone(request),
264
+ client: { ...this.identity },
265
+ }));
266
+ }
267
+ async writeWorkspaceFile(request) {
268
+ this.requireConnection();
269
+ return structuredClone(await this.transport.request('workspace.file.write', {
270
+ ...structuredClone(request),
271
+ client: { ...this.identity },
272
+ }));
273
+ }
274
+ async runWorkspaceCommand(request) {
275
+ this.requireConnection();
276
+ return structuredClone(await this.transport.request('workspace.command.run', {
277
+ ...structuredClone(request),
278
+ client: { ...this.identity },
279
+ }));
280
+ }
281
+ async startWorkspaceTerminal(request) {
282
+ this.requireConnection();
283
+ return structuredClone(await this.transport.request('workspace.terminal.start', {
284
+ ...structuredClone(request),
285
+ client: { ...this.identity },
286
+ }));
287
+ }
288
+ async stopWorkspaceTerminal(request) {
289
+ this.requireConnection();
290
+ return structuredClone(await this.transport.request('workspace.terminal.stop', {
291
+ ...structuredClone(request),
292
+ client: { ...this.identity },
293
+ }));
294
+ }
295
+ async startWorkspacePty(request) {
296
+ this.requireConnection();
297
+ return structuredClone(await this.transport.request('workspace.pty.start', {
298
+ ...structuredClone(request),
299
+ client: { ...this.identity },
300
+ }));
301
+ }
302
+ async snapshotWorkspacePty(request) {
303
+ this.requireConnection();
304
+ return structuredClone(await this.transport.request('workspace.pty.snapshot', {
305
+ ...structuredClone(request),
306
+ client: { ...this.identity },
307
+ }));
308
+ }
309
+ async inputWorkspacePty(request) {
310
+ this.requireConnection();
311
+ return structuredClone(await this.transport.request('workspace.pty.input', {
312
+ ...structuredClone(request),
313
+ client: { ...this.identity },
314
+ }));
315
+ }
316
+ async resizeWorkspacePty(request) {
317
+ this.requireConnection();
318
+ return structuredClone(await this.transport.request('workspace.pty.resize', {
319
+ ...structuredClone(request),
320
+ client: { ...this.identity },
321
+ }));
322
+ }
323
+ async clearWorkspacePty(request) {
324
+ this.requireConnection();
325
+ return structuredClone(await this.transport.request('workspace.pty.clear', {
326
+ ...structuredClone(request),
327
+ client: { ...this.identity },
328
+ }));
329
+ }
330
+ async stopWorkspacePty(request) {
331
+ this.requireConnection();
332
+ return structuredClone(await this.transport.request('workspace.pty.stop', {
333
+ ...structuredClone(request),
334
+ client: { ...this.identity },
335
+ }));
336
+ }
337
+ async startTurn(request, options = {}) {
338
+ this.requireConnection();
339
+ const response = await this.transport.request('turn.start', {
340
+ ...structuredClone(request),
341
+ command: this.createCommandContext(options, `turn:start:${request.conversationId}:${request.requestId}`),
342
+ });
343
+ if (!isAgentTurnStartResult(response)) {
344
+ throw new AgentHostProtocolError('invalid_response', 'Agent host returned an invalid turn-start result.');
345
+ }
346
+ return structuredClone(response);
347
+ }
348
+ async cancelTurn(request, options = {}) {
349
+ this.requireConnection();
350
+ const response = await this.transport.request('turn.cancel', {
351
+ ...structuredClone(request),
352
+ command: this.createCommandContext(options, `turn:cancel:${request.conversationId}:${request.requestId}`),
353
+ });
354
+ if (!isAgentTurnCancelResult(response)) {
355
+ throw new AgentHostProtocolError('invalid_response', 'Agent host returned an invalid turn-cancel result.');
356
+ }
357
+ return structuredClone(response);
358
+ }
359
+ async answerChooseDirectory(request) {
360
+ this.requireConnection();
361
+ return structuredClone(await this.transport.request('elicitation.choose-directory.answer', structuredClone(request)));
362
+ }
363
+ async answerWorkspacePlacement(request) {
364
+ this.requireConnection();
365
+ return structuredClone(await this.transport.request('elicitation.workspace-placement.answer', structuredClone(request)));
366
+ }
367
+ async answerPermission(request) {
368
+ this.requireConnection();
369
+ return structuredClone(await this.transport.request('elicitation.permission.answer', structuredClone(request)));
370
+ }
371
+ async answerAskUser(request) {
372
+ this.requireConnection();
373
+ return structuredClone(await this.transport.request('elicitation.ask-user.answer', structuredClone(request)));
374
+ }
375
+ async listSdkSessions(request = {}) {
376
+ return this.requestSdkControl('sdk.sessions.list', request);
377
+ }
378
+ async showSdkSession(request) {
379
+ return this.requestSdkControl('sdk.sessions.show', request);
380
+ }
381
+ async attachSdkSession(request) {
382
+ return this.requestSdkControl('sdk.sessions.attach', request);
383
+ }
384
+ async detachSdkSession(request) {
385
+ return this.requestSdkControl('sdk.sessions.detach', request);
386
+ }
387
+ async deleteSdkSession(request) {
388
+ return this.requestSdkControl('sdk.sessions.delete', request);
389
+ }
390
+ async cleanSdkSessions(request) {
391
+ return this.requestSdkControl('sdk.sessions.clean', request);
392
+ }
393
+ async listSdkCheckpoints(request) {
394
+ return this.requestSdkControl('sdk.checkpoints.list', request);
395
+ }
396
+ async restoreSdkCheckpoint(request) {
397
+ return this.requestSdkControl('sdk.checkpoints.restore', request);
398
+ }
399
+ async deleteSdkCheckpoint(request) {
400
+ return this.requestSdkControl('sdk.checkpoints.delete', request);
401
+ }
402
+ async readSdkTaskOutput(request) {
403
+ return this.requestSdkControl('sdk.tasks.output', request);
404
+ }
405
+ async stopSdkTask(request) {
406
+ return this.requestSdkControl('sdk.tasks.stop', request);
407
+ }
408
+ /**
409
+ * ACP registry operations that run under the host's authority.
410
+ *
411
+ * Mirrors `requestEngineering`. Grouped by prefix so the next `acp.*` method
412
+ * needs no new helper here.
413
+ */
414
+ async requestAcp(method, request) {
415
+ // Written out rather than delegating to `requestEngineering` through a cast:
416
+ // the generics genuinely differ, and `as never` would have silenced that
417
+ // rather than resolved it. Four lines is cheaper than a lie.
418
+ this.requireConnection();
419
+ return structuredClone(await this.transport.request(method, {
420
+ ...structuredClone(request),
421
+ client: { ...this.identity },
422
+ }));
423
+ }
424
+ /**
425
+ * Reading a run's observed diff — the READ half of §2.9.
426
+ *
427
+ * Separate from `requestEngineering` for the same reason `requestAcp` is: the
428
+ * generics genuinely differ, and one helper covering both would need a cast
429
+ * that silences the difference rather than resolving it.
430
+ */
431
+ /** The fleet surface — ADE §9 step 6. Its own helper for the same reason
432
+ * `requestAcp` has one: the generics differ, and one helper covering both
433
+ * would need a cast that silences the difference rather than resolving it. */
434
+ /** Sessions — ADE §5.5. Its own helper for the same reason its siblings have
435
+ * one: the generics differ, and a shared helper would need a cast that
436
+ * silences the difference rather than resolving it. */
437
+ /** Intake — ADE §5.1. Its own helper for the same reason its siblings have
438
+ * one: the generics differ, and a shared helper would need a cast. */
439
+ /** Workspace knowledge — ADE §5.8. Its own helper like its siblings. */
440
+ async requestKnowledge(method, request) {
441
+ this.requireConnection();
442
+ return structuredClone(await this.transport.request(method, {
443
+ ...structuredClone(request),
444
+ client: { ...this.identity },
445
+ }));
446
+ }
447
+ async requestIntake(method, request) {
448
+ this.requireConnection();
449
+ return structuredClone(await this.transport.request(method, {
450
+ ...structuredClone(request),
451
+ client: { ...this.identity },
452
+ }));
453
+ }
454
+ async requestSession(method, request) {
455
+ this.requireConnection();
456
+ return structuredClone(await this.transport.request(method, {
457
+ ...structuredClone(request),
458
+ client: { ...this.identity },
459
+ }));
460
+ }
461
+ async requestFleet(method, request) {
462
+ this.requireConnection();
463
+ return structuredClone(await this.transport.request(method, {
464
+ ...structuredClone(request),
465
+ client: { ...this.identity },
466
+ }));
467
+ }
468
+ async requestRunObservation(method, request) {
469
+ this.requireConnection();
470
+ return structuredClone(await this.transport.request(method, {
471
+ ...structuredClone(request),
472
+ client: { ...this.identity },
473
+ }));
474
+ }
475
+ async requestEngineering(method, request) {
476
+ this.requireConnection();
477
+ return structuredClone(await this.transport.request(method, {
478
+ ...structuredClone(request),
479
+ client: { ...this.identity },
480
+ }));
481
+ }
482
+ subscribe(listener) {
483
+ return this.transport.subscribe(listener);
484
+ }
485
+ disconnect() {
486
+ this.handshake = null;
487
+ }
488
+ requireConnection() {
489
+ if (!this.handshake) {
490
+ throw new AgentHostProtocolError('not_connected', 'Connect to the XENO Agent host before making this request.');
491
+ }
492
+ }
493
+ async requestSdkControl(method, request) {
494
+ this.requireConnection();
495
+ return structuredClone(await this.transport.request(method, {
496
+ ...structuredClone(request),
497
+ client: { ...this.identity },
498
+ }));
499
+ }
500
+ createCommandContext(options, fallbackIdempotencyKey) {
501
+ return {
502
+ schemaVersion: 1,
503
+ commandId: options.commandId || createClientCommandId(),
504
+ idempotencyKey: options.idempotencyKey || fallbackIdempotencyKey,
505
+ client: { ...this.identity },
506
+ };
507
+ }
508
+ }
509
+ function createClientCommandId() {
510
+ return globalThis.crypto?.randomUUID?.()
511
+ || `agent-command-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
512
+ }
513
+ // 🔴 The local-IPC half (transport, lease reading, attach) is NOT re-exported here. It lives
514
+ // behind the Node-only subpath `@xenosystem/agent-interface-client/local`.
515
+ //
516
+ // It was re-exported from this entry when it was first extracted, and that was a real defect:
517
+ // `packages/ui` value-imports this module, so `node:net` and `node:fs/promises` were reaching
518
+ // the Electron RENDERER BUNDLE — breaking the secure-renderer invariant in `AGENTS.md`. The
519
+ // architecture guard caught it. See `src/local/index.ts` for the full reasoning, and
520
+ // `@xenosystem/agent-interface-host/node` for the same pattern applied to the host.
521
+ //
522
+ // A SURFACE that attaches over local IPC (the CLI, ADE §2.7) imports the subpath.
523
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,oCAAoC,EACpC,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,uBAAuB,EACvB,sBAAsB,GA4CvB,MAAM,sCAAsC,CAAA;AAa7C,MAAM,OAAO,eAAe;IACT,SAAS,CAAoB;IAC7B,QAAQ,CAAyB;IACjC,iBAAiB,CAAwB;IAClD,SAAS,GAA8B,IAAI,CAAA;IAEnD,YAAY,OAA+B;QACzC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;QACvC,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB;YAChD,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,iBAAiB,EAAE;YAClC,CAAC,CAAC;gBACE,GAAG,EAAE,oCAAoC;gBACzC,GAAG,EAAE,gCAAgC;aACtC,CAAA;IACP,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAA;IAC9B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAA;IACjC,CAAC;IAED;;;;;;OAMG;IACH,IAAI,cAAc;QAChB,OAAO,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;IAC7B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI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,OAAO,eAAe,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE;YAC1D,GAAG,eAAe,CAAC,OAAO,CAAC;YAC3B,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE;SACR,CAAC,CAAC,CAAA;IAC1B,CAAC;IAEO,oBAAoB,CAAC,OAAgC,EAAE,sBAA8B;QAC3F,OAAO;YACL,aAAa,EAAE,CAAU;YACzB,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,qBAAqB,EAAE;YACvD,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,sBAAsB;YAChE,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE;SAC7B,CAAA;IACH,CAAC;CACF;AAED,SAAS,qBAAqB;IAC5B,OAAO,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;WACnC,iBAAiB,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAA;AAC/E,CAAC;AAED,6FAA6F;AAC7F,2EAA2E;AAC3E,EAAE;AACF,8FAA8F;AAC9F,8FAA8F;AAC9F,4FAA4F;AAC5F,qFAAqF;AACrF,oFAAoF;AACpF,EAAE;AACF,kFAAkF"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Attaching to a per-user Agent host — the SURFACE side of ADE §2.7.
3
+ *
4
+ * 🔴 `attachToLocalAgentHost` attaches or refuses; it can never become the host. There is no
5
+ * `createHostTransport` parameter, so there is nothing it could construct even if asked — the
6
+ * dangerous shape (a CLI started while no app is running WINS the lease and is then expected to
7
+ * *be* the host) is unrepresentable rather than merely forbidden.
8
+ *
9
+ * That property is why this file can live in a publishable package at all: everything here is
10
+ * what a thin client legitimately needs, and nothing here can take ownership. Acquisition and the
11
+ * host authority stay in the private `packages/host`.
12
+ */
13
+ import { type LocalAgentHostLeaseDescriptor } from './lease.js';
14
+ import { LocalAgentHostRpcClientTransport } from './transport.js';
15
+ /**
16
+ * 🔴 STRUCTURAL, not the concrete server/lease classes.
17
+ *
18
+ * The session only ever closes the server and releases or heartbeats the lease — three calls.
19
+ * Typing those fields as the host's concrete `LocalAgentHostRpcServer` and `LocalAgentHostLease`
20
+ * dragged the whole server implementation into this file, which is what kept the session
21
+ * unpublishable. Naming the three calls it actually makes decouples it, and the host's real
22
+ * classes satisfy these by shape with no adapter.
23
+ */
24
+ export interface ClosableAuthorityServer {
25
+ close(): Promise<void>;
26
+ }
27
+ export interface RenewableAuthorityLease {
28
+ release(): Promise<unknown>;
29
+ heartbeat(): Promise<unknown>;
30
+ }
31
+ export type LocalAgentHostAuthorityRole = 'owner' | 'attached-client';
32
+ export declare class LocalAgentHostAuthoritySession {
33
+ readonly role: LocalAgentHostAuthorityRole;
34
+ readonly descriptor: LocalAgentHostLeaseDescriptor;
35
+ readonly transport: LocalAgentHostRpcClientTransport;
36
+ private readonly server;
37
+ private readonly lease;
38
+ private readonly onAuthorityLost;
39
+ private heartbeatTimer;
40
+ private heartbeatPending;
41
+ private closed;
42
+ constructor(options: {
43
+ role: LocalAgentHostAuthorityRole;
44
+ descriptor: LocalAgentHostLeaseDescriptor;
45
+ transport: LocalAgentHostRpcClientTransport;
46
+ server?: ClosableAuthorityServer;
47
+ lease?: RenewableAuthorityLease;
48
+ heartbeatIntervalMs?: number;
49
+ onAuthorityLost?: (error: Error) => void;
50
+ });
51
+ close(): Promise<void>;
52
+ private heartbeat;
53
+ }
54
+ /**
55
+ * Elects the one local authority. Only the elected owner invokes
56
+ * createHostTransport; every other process attaches to its authenticated RPC
57
+ * endpoint, which prevents duplicate provider processes and split-brain state.
58
+ */
59
+ /**
60
+ * Why a surface could not attach. The REASON, not a boolean.
61
+ *
62
+ * 🔴 A CLI needs to tell its user what to do next, and "could not connect"
63
+ * does not. "No host is running" means start the app; "protocol mismatch" means
64
+ * the two builds disagree and one needs updating; "unreachable" means a host
65
+ * claims to be there and is not answering, which is a different problem again.
66
+ * Collapsing them sends a person to fix the wrong thing.
67
+ */
68
+ export type AttachLocalAgentHostRefusal = {
69
+ reason: 'no-host';
70
+ detail: string;
71
+ } | {
72
+ reason: 'host-gone';
73
+ detail: string;
74
+ } | {
75
+ reason: 'protocol-mismatch';
76
+ detail: string;
77
+ hostProtocol: number;
78
+ clientProtocol: number;
79
+ } | {
80
+ reason: 'unreachable';
81
+ detail: string;
82
+ };
83
+ export type AttachLocalAgentHostResult = {
84
+ attached: true;
85
+ session: LocalAgentHostAuthoritySession;
86
+ } | ({
87
+ attached: false;
88
+ } & AttachLocalAgentHostRefusal);
89
+ export interface AttachToLocalAgentHostOptions {
90
+ rootDirectory: string;
91
+ protocolVersion?: number;
92
+ connectTimeoutMs?: number;
93
+ requestTimeoutMs?: number;
94
+ /** Injected for tests; production reads the real clock and process table. */
95
+ now?: () => number;
96
+ staleAfterMs?: number;
97
+ isProcessAlive?: (pid: number) => boolean;
98
+ }
99
+ /**
100
+ * Attach to a host someone else owns — and NEVER become one.
101
+ *
102
+ * 🔴 This exists because `startLocalAgentHostAuthority` is acquire-or-attach,
103
+ * and for a surface that is the wrong shape in the most dangerous way: a CLI
104
+ * started while no app is running would WIN the lease and then be asked to
105
+ * build a host, which a thin client has no business owning. ADE §2.7 is
106
+ * explicit that `xeno-agent-cli` "becomes a client of the same per-user host";
107
+ * a client that can silently become the server is not that.
108
+ *
109
+ * 🔴 The defect is made UNREPRESENTABLE rather than documented: there is no
110
+ * `createHostTransport` parameter here, so there is nothing this function could
111
+ * construct even if it wanted to. It inspects, it connects, or it refuses with
112
+ * a reason.
113
+ */
114
+ export declare function attachToLocalAgentHost(options: AttachToLocalAgentHostOptions): Promise<AttachLocalAgentHostResult>;
115
+ export declare function connectBeforeDeadline(transport: LocalAgentHostRpcClientTransport, timeoutMs: number): Promise<void>;
116
+ //# sourceMappingURL=attach.d.ts.map
@@ -0,0 +1 @@
1
+ {"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