agent-comms 2.9.0 → 2.10.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.
Files changed (37) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +1 -1
  4. package/dist/core/mesh-store.d.ts +26 -2
  5. package/dist/core/mesh-store.d.ts.map +1 -1
  6. package/dist/core/mesh-store.js +143 -24
  7. package/dist/core/mesh-store.js.map +1 -1
  8. package/dist/test/delivery-receipt.helper.js +44 -10
  9. package/dist/test/delivery-receipt.helper.js.map +1 -1
  10. package/dist/test/identity-restart.integration.test.js +18 -2
  11. package/dist/test/identity-restart.integration.test.js.map +1 -1
  12. package/dist/test/invite-replay.test.d.ts +5 -0
  13. package/dist/test/invite-replay.test.d.ts.map +1 -0
  14. package/dist/test/invite-replay.test.js +67 -0
  15. package/dist/test/invite-replay.test.js.map +1 -0
  16. package/dist/test/mesh-e2e.integration.test.js +20 -4
  17. package/dist/test/mesh-e2e.integration.test.js.map +1 -1
  18. package/dist/test/mesh-smoke.runner.js +15 -1
  19. package/dist/test/mesh-smoke.runner.js.map +1 -1
  20. package/dist/test/room-send-retry-queue.test.d.ts +5 -0
  21. package/dist/test/room-send-retry-queue.test.d.ts.map +1 -0
  22. package/dist/test/room-send-retry-queue.test.js +142 -0
  23. package/dist/test/room-send-retry-queue.test.js.map +1 -0
  24. package/dist/test/room-send-retry.integration.test.d.ts +5 -0
  25. package/dist/test/room-send-retry.integration.test.d.ts.map +1 -0
  26. package/dist/test/{downtime-replay.integration.test.js → room-send-retry.integration.test.js} +16 -21
  27. package/dist/test/room-send-retry.integration.test.js.map +1 -0
  28. package/dist/test/state-sync-convergence.test.js +23 -1
  29. package/dist/test/state-sync-convergence.test.js.map +1 -1
  30. package/package.json +2 -2
  31. package/dist/test/downtime-replay.integration.test.d.ts +0 -7
  32. package/dist/test/downtime-replay.integration.test.d.ts.map +0 -1
  33. package/dist/test/downtime-replay.integration.test.js.map +0 -1
  34. package/dist/test/downtime-replay.test.d.ts +0 -5
  35. package/dist/test/downtime-replay.test.d.ts.map +0 -1
  36. package/dist/test/downtime-replay.test.js +0 -156
  37. package/dist/test/downtime-replay.test.js.map +0 -1
@@ -15,7 +15,7 @@
15
15
  "url": "https://github.com/ExaDev/agent-comms.git"
16
16
  },
17
17
  "description": "Cross-harness LLM agent communication mesh — rooms, DMs, and presence",
18
- "version": "2.9.0"
18
+ "version": "2.10.0"
19
19
  }
20
20
  ]
21
21
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agent-comms",
3
3
  "description": "Cross-harness LLM agent communication mesh — rooms, DMs, and presence",
4
- "version": "2.9.0",
4
+ "version": "2.10.0",
5
5
  "author": {
6
6
  "name": "ExaDev"
7
7
  },
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![GitHub](https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=white)](https://github.com/ExaDev/agent-comms)
4
4
  [![npm](https://img.shields.io/badge/npm-CB3837?logo=npm&logoColor=white)](https://www.npmjs.com/package/agent-comms)
5
- [![version](https://img.shields.io/badge/version-2.9.0-blue)](https://github.com/ExaDev/agent-comms/releases/tag/v2.9.0)
5
+ [![version](https://img.shields.io/badge/version-2.10.0-blue)](https://github.com/ExaDev/agent-comms/releases/tag/v2.10.0)
6
6
  [![CI](https://img.shields.io/github/actions/workflow/status/ExaDev/agent-comms/ci.yml?branch=main)](https://github.com/ExaDev/agent-comms/actions)
7
7
 
8
8
  Cross-harness communication mesh for LLM agents: rooms, DMs, presence, and visibility over TCP with zero filesystem dependencies.
@@ -25,7 +25,8 @@ import type { IdentitySlot } from "./identity-store.js";
25
25
  import type { MeshStatePatch } from "./wire-protocol.js";
26
26
  import type { MeshTransport, TransportEvents } from "./transport.js";
27
27
  import type { CommsStore } from "./comms-store.js";
28
- import type { AgentIdentity, DeliveryEvent, DmMessage, MeshVisibility, NetworkInterface, Room, RoomMessage, RoomType, StreamingBehavior, Visibility } from "./types.js";
28
+ import { StreamingBehavior } from "./types.js";
29
+ import type { AgentIdentity, DeliveryEvent, DmMessage, MeshVisibility, NetworkInterface, Room, RoomMessage, RoomType, Visibility } from "./types.js";
29
30
  import type { ListenerInfo } from "./transport.js";
30
31
  /** The identity/clock/persistence collaborators MeshStore mints and persists room-membership grants against. Set via setIdentity(), mirroring the transport's own setTransport() contract. */
31
32
  export interface MeshStoreIdentity {
@@ -44,6 +45,8 @@ export declare class MeshStore implements CommsStore {
44
45
  private dms;
45
46
  private deliveryQueues;
46
47
  private identityCache;
48
+ /** Directed room.send requests that failed because their target member wasn't reachable at send time, held for retry when that member's own connection is (re)established -- the wire-authenticated fan-out's substitute for the legacy full-state-sync's own automatic eventual consistency, since a direct request to a disconnected peer fails immediately with no protocol-level retry of its own. Keyed by member device-id hex, bounded oldest-first per member with the same cap ordinary delivery queues use. */
49
+ private pendingRoomSends;
47
50
  private transport;
48
51
  private storeIdentity;
49
52
  private peerInfo;
@@ -185,14 +188,26 @@ export declare class MeshStore implements CommsStore {
185
188
  * Room verb handlers this store registers with its own WireMeshTransport, keyed by params.verb per room-router.ts's own dispatch discipline. A getter (not a plain field) so every access reads through the current `this` binding without needing a constructor-time closure -- mirrors the `events` getter's own reasoning below.
186
189
  */
187
190
  get roomVerbHandlers(): Partial<Record<string, RoomVerbHandler>>;
191
+ /** Reads the "reply" message-ref out of a room.send's own params (if any) and returns the hex id it names -- room.send's replyTo carries a single parent message, so the first reply-relation ref is the one that matters; any further refs are a future relation this handler doesn't yet act on. */
192
+ private static replyToFromRefs;
193
+ /** Reads room.send's own "streaming-behavior" extension field (open params tail, not a named schema field) and validates it against the same StreamingBehavior contract every other delivery path already enforces -- an unrecognised or malformed value is dropped rather than rejecting the whole send, matching core/room's own obligation to ignore what it doesn't understand instead of failing closed on an extension field. */
194
+ private static streamingBehaviorFromParams;
188
195
  /**
189
- * Receiving side of a directed room.send (P3.5): verifies the presented token against all six of core/room's own obligations, then delivers the message locally exactly once -- the manage-response this returns IS the delivery receipt, so there is no separate "delivered" event to emit the way the legacy broadcastPatch path needed one.
196
+ * Receiving side of a directed room.send (P3.5): verifies the presented token against all six of core/room's own obligations, then delivers the message locally exactly once -- the manage-response this returns IS the delivery receipt, so there is no separate "delivered" event to emit the way the legacy broadcastPatch path needed one. Branches on the room-path's own shape: an owner-named path stores a RoomMessage in this room's own history and fires a room_message event; a DM path stores a DmMessage keyed by the same dm-path sendDm already uses and fires a dm event -- both ride the identical room:member-gated verb, since a DM is just a room-path variant, not a separate verb.
190
197
  */
191
198
  private handleRoomSend;
192
199
  /**
193
200
  * Sends one directed room.send to a single member's own session, attaching this store's own persisted room:member token for the given room path -- the primitive P3.5's own directed fan-out (deliverToRoom) will loop over per member once it replaces the legacy broadcastPatch path this store still uses for message delivery today. Throws if this store holds no token for the room: never a member, or a token that expired or was revoked with nothing fresh persisted in its place.
194
201
  */
195
202
  sendRoomMessageDirected(roomPath: string, memberId: string, text: string): Promise<void>;
203
+ /** Records a room.send that couldn't reach memberId right now, for a later flushPendingRoomSends to retry once that member reconnects. Bounded oldest-first with the same cap ordinary delivery queues use, so an indefinitely-offline member cannot grow this without limit. */
204
+ private queuePendingRoomSend;
205
+ /**
206
+ * Sends one directed room.send to a single member, queuing it for retry instead of throwing when the member isn't currently reachable -- the fan-out's own per-recipient primitive, distinct from sendRoomMessageDirected's deliberate throw-on-failure contract for a caller sending to one specific, known recipient. Silently drops a send this store no longer holds a token for (no longer a member of the room) rather than queuing something that will only fail again on retry.
207
+ */
208
+ private deliverRoomSendToMember;
209
+ /** Retries every room.send queued for memberId since it was last reachable, dropping (not re-queuing) any whose room this store no longer holds a token for. Called once a connection to memberId is (re)established -- handlePeerConnected fires for both a fresh introduction and a reconnection after downtime, exactly the two cases a queued send needs to be retried on. */
210
+ private flushPendingRoomSends;
196
211
  /**
197
212
  * Owner-side admission for an incoming room.join request, against either a named room this store owns or a DM path this store is a participant of. Named-room admission always needs a human decision; DM admission needs one only for the party being contacted first -- the reply half of the two-round consent flow (section 6) auto-approves, since a reply on a path this node itself opened is not unsolicited contact.
198
213
  */
@@ -225,14 +240,23 @@ export declare class MeshStore implements CommsStore {
225
240
  * The requester's own half of section 6's two-round DM consent flow: sends an ungated room.join scoped to dmRoomPath(this, counterpart) directly to the counterpart, records having initiated it so the counterpart's own reciprocal room.join back auto-approves rather than surfacing as a fresh, unsolicited request, and persists whatever grant comes back. Deliberately outside the CommsStore interface, like connection approval, since it is a wire-mesh-specific concern FileStore has no equivalent for. Safe to call again for the same counterpart later (e.g. after an earlier request expired or was rejected) -- it always sends a fresh request rather than checking for an existing token first.
226
241
  */
227
242
  requestDmAccess(counterpart: string): Promise<void>;
243
+ /**
244
+ * Joins a room. For this store's own identity, "already known locally" is not the right gate for skipping real admission: the legacy full-state-sync replicates a room's metadata to every mesh-connected peer the moment it's created, well before that peer has ever been admitted, so a room already present in this.rooms says nothing about whether this store actually holds a valid room:member token for it. The real gate is that token's presence -- absent, this always goes through joinRemoteRoom's real wire-level admission regardless of what this.rooms already knows, so a peer that merely heard about a room never mistakes hearing about it for having joined it. Joining on behalf of a DIFFERENT agentId (this store's own convergence/admin bookkeeping, exercised directly by state-sync-convergence.test.ts) is untouched -- that's a pure local CRDT mutation with no admission concept at all.
245
+ */
228
246
  joinRoom(roomId: string, agentId: string): Promise<Room>;
229
247
  leaveRoom(roomId: string, agentId: string): Promise<void>;
230
248
  inviteToRoom(roomId: string, targetId: string, inviterId: string): Promise<void>;
231
249
  declineInvite(roomId: string, agentId: string, reason: string): Promise<void>;
232
250
  kickFromRoom(roomId: string, targetId: string, kickerId: string): Promise<void>;
233
251
  destroyRoom(roomId: string, agentId: string): Promise<void>;
252
+ /**
253
+ * Sends a room message via a real, wire-authenticated room.send fan-out (P3.5): one directed request per member, each carrying this sender's own persisted room:member token, rather than the legacy broadcastPatch's full-state replication. A member unreachable right now is queued for retry (see deliverRoomSendToMember/flushPendingRoomSends) instead of blocking or failing the whole send -- delivery to any one recipient is independent of every other.
254
+ */
234
255
  sendRoomMessage(roomId: string, from: string, content: string, replyTo?: string, streamingBehavior?: StreamingBehavior): Promise<RoomMessage>;
235
256
  readRoomMessages(roomId: string, since?: string): Promise<RoomMessage[]>;
257
+ /**
258
+ * Sends a DM via the same wire-authenticated room.send fan-out sendRoomMessage uses (P3.5): a DM is just a dm-shaped room path with exactly one other member, so it rides the identical mechanism rather than a separate one. Self-DM is the one exception -- a purely local scratchpad note that never leaves the process, so it needs no token and no wire round trip at all.
259
+ */
236
260
  sendDm(from: string, to: string, content: string, streamingBehavior?: StreamingBehavior): Promise<DmMessage>;
237
261
  deliver(agentId: string, event: DeliveryEvent): Promise<void>;
238
262
  drainDelivery(agentId: string): Promise<DeliveryEvent[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"mesh-store.d.ts","sourceRoot":"","sources":["../../src/core/mesh-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAQ/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AASxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAe,cAAc,EAAY,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAEV,aAAa,EACb,eAAe,EAChB,MAAM,gBAAgB,CAAC;AACxB,OA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B,IAAI,gBAAgB,EAAE;IAqBpC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAItE,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,QAAQ,IAAI,OAAO,EAAE;IAIrB,wBAAwB,IAAI,MAAM;IAIlC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5C,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9C,sBAAsB,IAAI,MAAM,EAAE;IAIlC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;YAQnB,qBAAqB;YAYrB,kBAAkB;YAalB,oBAAoB;YAqBpB,iBAAiB;YA+BjB,kBAAkB;IAqBhC,OAAO,CAAC,sBAAsB;IAY9B,OAAO,CAAC,iCAAiC;IAgBnC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAuBhC"}
@@ -23,12 +23,13 @@ import { MdnsDiscoveryBackend } from "./discovery-mdns.js";
23
23
  import { TailscaleDiscoveryBackend } from "./discovery-tailscale.js";
24
24
  import { FederationManager } from "./federation.js";
25
25
  import { getCertificateFingerprint } from "./identity.js";
26
- import { bytesToHex, deviceIdFromHex, deviceIdToHex, } from "wire-mesh-core/domain/device-id";
26
+ import { bytesFromHex, bytesToHex, deviceIdFromHex, deviceIdToHex, } from "wire-mesh-core/domain/device-id";
27
27
  import { mintCapabilityToken } from "wire-mesh-core/domain/tokens";
28
28
  import { roomJoinOkSchema, roomSendSchema, } from "wire-mesh-core/generated/protocol";
29
29
  import { ROOM_MEMBER_CAPABILITY, verifyRoomToken, } from "./room-token-verification.js";
30
30
  import { loadRoomTokens, saveRoomToken } from "./identity-store.js";
31
31
  import { randomId } from "./random-id.js";
32
+ import { StreamingBehavior } from "./types.js";
32
33
  // ---------------------------------------------------------------------------
33
34
  // Constants
34
35
  // ---------------------------------------------------------------------------
@@ -77,6 +78,8 @@ export class MeshStore {
77
78
  dms = new Map();
78
79
  deliveryQueues = new Map();
79
80
  identityCache = new Map();
81
+ /** Directed room.send requests that failed because their target member wasn't reachable at send time, held for retry when that member's own connection is (re)established -- the wire-authenticated fan-out's substitute for the legacy full-state-sync's own automatic eventual consistency, since a direct request to a disconnected peer fails immediately with no protocol-level retry of its own. Keyed by member device-id hex, bounded oldest-first per member with the same cap ordinary delivery queues use. */
82
+ pendingRoomSends = new Map();
80
83
  transport;
81
84
  storeIdentity;
82
85
  peerInfo = new Map();
@@ -252,6 +255,7 @@ export class MeshStore {
252
255
  state,
253
256
  });
254
257
  }
258
+ await this.flushPendingRoomSends(handle.id);
255
259
  }
256
260
  /**
257
261
  * Merge a peer's state snapshot into the local state. Agents and rooms
@@ -967,8 +971,21 @@ export class MeshStore {
967
971
  "room.send": (request, handle) => this.handleRoomSend(request, handle),
968
972
  };
969
973
  }
974
+ /** Reads the "reply" message-ref out of a room.send's own params (if any) and returns the hex id it names -- room.send's replyTo carries a single parent message, so the first reply-relation ref is the one that matters; any further refs are a future relation this handler doesn't yet act on. */
975
+ static replyToFromRefs(refs) {
976
+ const reply = refs?.find((ref) => ref.relation === "reply");
977
+ return reply === undefined ? undefined : bytesToHex(reply.id);
978
+ }
979
+ /** Reads room.send's own "streaming-behavior" extension field (open params tail, not a named schema field) and validates it against the same StreamingBehavior contract every other delivery path already enforces -- an unrecognised or malformed value is dropped rather than rejecting the whole send, matching core/room's own obligation to ignore what it doesn't understand instead of failing closed on an extension field. */
980
+ static streamingBehaviorFromParams(params) {
981
+ const raw = params["streaming-behavior"];
982
+ if (raw === undefined)
983
+ return undefined;
984
+ const result = StreamingBehavior.safeParse(raw);
985
+ return result.success ? result.data : undefined;
986
+ }
970
987
  /**
971
- * Receiving side of a directed room.send (P3.5): verifies the presented token against all six of core/room's own obligations, then delivers the message locally exactly once -- the manage-response this returns IS the delivery receipt, so there is no separate "delivered" event to emit the way the legacy broadcastPatch path needed one.
988
+ * Receiving side of a directed room.send (P3.5): verifies the presented token against all six of core/room's own obligations, then delivers the message locally exactly once -- the manage-response this returns IS the delivery receipt, so there is no separate "delivered" event to emit the way the legacy broadcastPatch path needed one. Branches on the room-path's own shape: an owner-named path stores a RoomMessage in this room's own history and fires a room_message event; a DM path stores a DmMessage keyed by the same dm-path sendDm already uses and fires a dm event -- both ride the identical room:member-gated verb, since a DM is just a room-path variant, not a separate verb.
972
989
  */
973
990
  async handleRoomSend(request, handle) {
974
991
  const roomPath = request.scope.path;
@@ -994,18 +1011,43 @@ export class MeshStore {
994
1011
  return { result: "error", code: "malformed_params" };
995
1012
  }
996
1013
  const params = parsedParams.data;
997
- const message = {
998
- id: bytesToHex(params["message-id"]),
999
- from: handle.id,
1000
- room: roomPath,
1001
- content: params.text,
1002
- timestamp: new Date(params["sent-at"]).toISOString(),
1003
- readBy: [handle.id],
1004
- };
1005
- const history = this.messages.get(roomPath) ?? [];
1006
- history.push(message);
1007
- this.messages.set(roomPath, history);
1008
- const event = { type: "room_message", message };
1014
+ const replyTo = MeshStore.replyToFromRefs(params.refs);
1015
+ const streamingBehavior = MeshStore.streamingBehaviorFromParams(params);
1016
+ const id = bytesToHex(params["message-id"]);
1017
+ const timestamp = new Date(params["sent-at"]).toISOString();
1018
+ const parsedPath = parseRoomPath(roomPath);
1019
+ let event;
1020
+ if (parsedPath.kind === "dm") {
1021
+ const message = {
1022
+ id,
1023
+ from: handle.id,
1024
+ to: this.peerId,
1025
+ content: params.text,
1026
+ timestamp,
1027
+ readBy: [handle.id],
1028
+ ...(streamingBehavior !== undefined && { streamingBehavior }),
1029
+ };
1030
+ const history = this.dms.get(roomPath) ?? [];
1031
+ history.push(message);
1032
+ this.dms.set(roomPath, history);
1033
+ event = { type: "dm", message };
1034
+ }
1035
+ else {
1036
+ const message = {
1037
+ id,
1038
+ from: handle.id,
1039
+ room: roomPath,
1040
+ content: params.text,
1041
+ timestamp,
1042
+ readBy: [handle.id],
1043
+ ...(replyTo !== undefined && { replyTo }),
1044
+ ...(streamingBehavior !== undefined && { streamingBehavior }),
1045
+ };
1046
+ const history = this.messages.get(roomPath) ?? [];
1047
+ history.push(message);
1048
+ this.messages.set(roomPath, history);
1049
+ event = { type: "room_message", message };
1050
+ }
1009
1051
  this.queueDelivery(this.peerId, event);
1010
1052
  this.fireLocalDelivery(this.peerId, event);
1011
1053
  return { result: "ok" };
@@ -1032,6 +1074,38 @@ export class MeshStore {
1032
1074
  throw new CommsError(`room.send to ${memberId} for ${roomPath} failed (${outcome.code})`, "SEND_FAILED");
1033
1075
  }
1034
1076
  }
1077
+ /** Records a room.send that couldn't reach memberId right now, for a later flushPendingRoomSends to retry once that member reconnects. Bounded oldest-first with the same cap ordinary delivery queues use, so an indefinitely-offline member cannot grow this without limit. */
1078
+ queuePendingRoomSend(memberId, roomPath, params) {
1079
+ const queue = this.pendingRoomSends.get(memberId) ?? [];
1080
+ queue.push({ roomPath, params });
1081
+ if (queue.length > MAX_QUEUED_DELIVERIES_PER_AGENT) {
1082
+ queue.splice(0, queue.length - MAX_QUEUED_DELIVERIES_PER_AGENT);
1083
+ }
1084
+ this.pendingRoomSends.set(memberId, queue);
1085
+ }
1086
+ /**
1087
+ * Sends one directed room.send to a single member, queuing it for retry instead of throwing when the member isn't currently reachable -- the fan-out's own per-recipient primitive, distinct from sendRoomMessageDirected's deliberate throw-on-failure contract for a caller sending to one specific, known recipient. Silently drops a send this store no longer holds a token for (no longer a member of the room) rather than queuing something that will only fail again on retry.
1088
+ */
1089
+ async deliverRoomSendToMember(memberId, roomPath, token, params) {
1090
+ const outcome = await this.requireTransport().sendRoomRequest(memberId, { verb: ROOM_MEMBER_CAPABILITY, params }, { kind: "room", path: roomPath }, token);
1091
+ if (outcome.result !== "ok") {
1092
+ this.queuePendingRoomSend(memberId, roomPath, params);
1093
+ }
1094
+ }
1095
+ /** Retries every room.send queued for memberId since it was last reachable, dropping (not re-queuing) any whose room this store no longer holds a token for. Called once a connection to memberId is (re)established -- handlePeerConnected fires for both a fresh introduction and a reconnection after downtime, exactly the two cases a queued send needs to be retried on. */
1096
+ async flushPendingRoomSends(memberId) {
1097
+ const queue = this.pendingRoomSends.get(memberId);
1098
+ if (queue === undefined || queue.length === 0)
1099
+ return;
1100
+ this.pendingRoomSends.delete(memberId);
1101
+ const { slot } = this.requireIdentity();
1102
+ for (const pending of queue) {
1103
+ const token = loadRoomTokens(slot)[pending.roomPath];
1104
+ if (token === undefined)
1105
+ continue;
1106
+ await this.deliverRoomSendToMember(memberId, pending.roomPath, token, pending.params);
1107
+ }
1108
+ }
1035
1109
  /**
1036
1110
  * Owner-side admission for an incoming room.join request, against either a named room this store owns or a DM path this store is a participant of. Named-room admission always needs a human decision; DM admission needs one only for the party being contacted first -- the reply half of the two-round consent flow (section 6) auto-approves, since a reply on a path this node itself opened is not unsolicited contact.
1037
1111
  */
@@ -1229,7 +1303,16 @@ export class MeshStore {
1229
1303
  const { slot } = this.requireIdentity();
1230
1304
  saveRoomToken(slot, dmPath, parsedOutcome.data["granted-token"]);
1231
1305
  }
1306
+ /**
1307
+ * Joins a room. For this store's own identity, "already known locally" is not the right gate for skipping real admission: the legacy full-state-sync replicates a room's metadata to every mesh-connected peer the moment it's created, well before that peer has ever been admitted, so a room already present in this.rooms says nothing about whether this store actually holds a valid room:member token for it. The real gate is that token's presence -- absent, this always goes through joinRemoteRoom's real wire-level admission regardless of what this.rooms already knows, so a peer that merely heard about a room never mistakes hearing about it for having joined it. Joining on behalf of a DIFFERENT agentId (this store's own convergence/admin bookkeeping, exercised directly by state-sync-convergence.test.ts) is untouched -- that's a pure local CRDT mutation with no admission concept at all.
1308
+ */
1232
1309
  async joinRoom(roomId, agentId) {
1310
+ if (agentId === this.peerId) {
1311
+ const { slot } = this.requireIdentity();
1312
+ if (loadRoomTokens(slot)[roomId] === undefined) {
1313
+ return this.joinRemoteRoom(roomId, agentId);
1314
+ }
1315
+ }
1233
1316
  const room = this.rooms.get(roomId);
1234
1317
  if (!room)
1235
1318
  return this.joinRemoteRoom(roomId, agentId);
@@ -1390,37 +1473,54 @@ export class MeshStore {
1390
1473
  // -----------------------------------------------------------------------
1391
1474
  // CommsStore — Messages
1392
1475
  // -----------------------------------------------------------------------
1476
+ /**
1477
+ * Sends a room message via a real, wire-authenticated room.send fan-out (P3.5): one directed request per member, each carrying this sender's own persisted room:member token, rather than the legacy broadcastPatch's full-state replication. A member unreachable right now is queued for retry (see deliverRoomSendToMember/flushPendingRoomSends) instead of blocking or failing the whole send -- delivery to any one recipient is independent of every other.
1478
+ */
1393
1479
  async sendRoomMessage(roomId, from, content, replyTo, streamingBehavior) {
1394
1480
  const room = this.rooms.get(roomId);
1395
1481
  if (!room)
1396
1482
  throw new CommsError(`Room ${roomId} not found`, "ROOM_NOT_FOUND");
1397
1483
  if (!room.members.includes(from))
1398
1484
  throw new CommsError(`Not a member of ${roomId}`, "NOT_MEMBER");
1399
- const id = `${String(Date.now())}-${nanoid(6)}`;
1485
+ const { slot, clock } = this.requireIdentity();
1486
+ const token = loadRoomTokens(slot)[roomId];
1487
+ if (token === undefined) {
1488
+ throw new CommsError(`No room:member token for ${roomId}`, "NOT_MEMBER");
1489
+ }
1490
+ const messageId = randomId();
1491
+ const id = bytesToHex(messageId);
1400
1492
  const message = {
1401
1493
  id,
1402
1494
  from,
1403
1495
  room: roomId,
1404
1496
  content,
1405
1497
  timestamp: new Date().toISOString(),
1406
- replyTo,
1407
1498
  readBy: [from],
1499
+ ...(replyTo !== undefined && { replyTo }),
1408
1500
  ...(streamingBehavior !== undefined && { streamingBehavior }),
1409
1501
  };
1410
1502
  const arr = this.messages.get(roomId) ?? [];
1411
1503
  arr.push(message);
1412
1504
  this.messages.set(roomId, arr);
1413
- await this.broadcastPatch({ type: "message_add", roomId, message });
1414
1505
  // Forward to federated links if the room is federated
1415
1506
  if (room.federated) {
1416
1507
  await this.federation.forwardRoomMessage(roomId, message);
1417
1508
  }
1509
+ const params = {
1510
+ verb: "room.send",
1511
+ "message-id": messageId,
1512
+ "sent-at": clock.now(),
1513
+ text: content,
1514
+ ...(replyTo !== undefined && {
1515
+ refs: [{ id: bytesFromHex(replyTo), relation: "reply" }],
1516
+ }),
1517
+ ...(streamingBehavior !== undefined && {
1518
+ "streaming-behavior": streamingBehavior,
1519
+ }),
1520
+ };
1418
1521
  for (const memberId of room.members) {
1419
1522
  if (memberId !== from) {
1420
- await this.deliverLocallyAndBroadcast(memberId, {
1421
- type: "room_message",
1422
- message,
1423
- });
1523
+ await this.deliverRoomSendToMember(memberId, roomId, token, params);
1424
1524
  }
1425
1525
  }
1426
1526
  return message;
@@ -1435,6 +1535,9 @@ export class MeshStore {
1435
1535
  // -----------------------------------------------------------------------
1436
1536
  // CommsStore — DMs
1437
1537
  // -----------------------------------------------------------------------
1538
+ /**
1539
+ * Sends a DM via the same wire-authenticated room.send fan-out sendRoomMessage uses (P3.5): a DM is just a dm-shaped room path with exactly one other member, so it rides the identical mechanism rather than a separate one. Self-DM is the one exception -- a purely local scratchpad note that never leaves the process, so it needs no token and no wire round trip at all.
1540
+ */
1438
1541
  async sendDm(from, to, content, streamingBehavior) {
1439
1542
  if (to !== from) {
1440
1543
  const recipient = this.agents.get(to);
@@ -1443,7 +1546,8 @@ export class MeshStore {
1443
1546
  if (recipient.visibility === "ghost")
1444
1547
  throw new CommsError(`Cannot DM agent ${to}`, "AGENT_NOT_FOUND");
1445
1548
  }
1446
- const id = `${String(Date.now())}-${nanoid(6)}`;
1549
+ const messageId = randomId();
1550
+ const id = bytesToHex(messageId);
1447
1551
  const message = {
1448
1552
  id,
1449
1553
  from,
@@ -1458,8 +1562,23 @@ export class MeshStore {
1458
1562
  const arr = this.dms.get(key) ?? [];
1459
1563
  arr.push(message);
1460
1564
  this.dms.set(key, arr);
1461
- await this.broadcastPatch({ type: "dm_add", key, message });
1462
- await this.deliverLocallyAndBroadcast(to, { type: "dm", message });
1565
+ if (to !== from) {
1566
+ const { slot, clock } = this.requireIdentity();
1567
+ const token = loadRoomTokens(slot)[key];
1568
+ if (token === undefined) {
1569
+ throw new CommsError(`No room:member token for ${key}`, "NOT_MEMBER");
1570
+ }
1571
+ const params = {
1572
+ verb: "room.send",
1573
+ "message-id": messageId,
1574
+ "sent-at": clock.now(),
1575
+ text: content,
1576
+ ...(streamingBehavior !== undefined && {
1577
+ "streaming-behavior": streamingBehavior,
1578
+ }),
1579
+ };
1580
+ await this.deliverRoomSendToMember(to, key, token, params);
1581
+ }
1463
1582
  return message;
1464
1583
  }
1465
1584
  // -----------------------------------------------------------------------