@joe-broadhead/messaging 0.7.0 → 0.7.1

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 (43) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/bin/messaging-mcp.js +649 -12
  3. package/dist/bin/messaging-relay.js +774 -20
  4. package/dist/bin/messaging.js +748 -15
  5. package/dist/bin/messagingd.js +785 -18
  6. package/dist/lib/modules/core/agent-tools.js +23 -4
  7. package/dist/lib/modules/core/conversation/context.js +80 -0
  8. package/dist/lib/modules/core/conversation/event.js +100 -0
  9. package/dist/lib/modules/core/conversation/ids.js +38 -0
  10. package/dist/lib/modules/core/conversation/link.js +35 -0
  11. package/dist/lib/modules/core/conversation/log.js +766 -0
  12. package/dist/lib/modules/core/conversation/ratchet.js +243 -0
  13. package/dist/lib/modules/core/conversation/seal.js +198 -0
  14. package/dist/lib/modules/core/index.js +10 -1
  15. package/dist/lib/modules/core/schema/common.js +56 -0
  16. package/dist/lib/modules/core/schema/conversation.js +292 -0
  17. package/dist/lib/modules/core/schema/errors.js +39 -0
  18. package/dist/lib/modules/core/schema/index.js +1 -0
  19. package/dist/lib/modules/core/testing.js +1 -0
  20. package/dist/lib/modules/core/version.js +1 -1
  21. package/dist/spec/messaging-v1.md +324 -6
  22. package/dist/types/core/agent-tools.d.ts +20 -2
  23. package/dist/types/core/conversation/context.d.ts +56 -0
  24. package/dist/types/core/conversation/event.d.ts +36 -0
  25. package/dist/types/core/conversation/ids.d.ts +18 -0
  26. package/dist/types/core/conversation/link.d.ts +16 -0
  27. package/dist/types/core/conversation/log.d.ts +142 -0
  28. package/dist/types/core/conversation/ratchet.d.ts +95 -0
  29. package/dist/types/core/conversation/seal.d.ts +47 -0
  30. package/dist/types/core/index.d.ts +8 -1
  31. package/dist/types/core/schema/common.d.ts +56 -0
  32. package/dist/types/core/schema/conversation.d.ts +1657 -0
  33. package/dist/types/core/schema/envelope.d.ts +6 -0
  34. package/dist/types/core/schema/errors.d.ts +38 -0
  35. package/dist/types/core/schema/index.d.ts +1 -0
  36. package/dist/types/core/schema/ipc/device.d.ts +6 -0
  37. package/dist/types/core/schema/ipc/shapes.d.ts +3 -0
  38. package/dist/types/core/schema/ipc/surfaces.d.ts +6 -0
  39. package/dist/types/core/schema/ipc.d.ts +15 -0
  40. package/dist/types/core/schema/relay.d.ts +12 -0
  41. package/dist/types/core/testing.d.ts +1 -0
  42. package/dist/types/core/version.d.ts +1 -1
  43. package/package.json +1 -1
@@ -0,0 +1,292 @@
1
+ /**
2
+ * Conversations (spec §16): one log per conversation, sequenced by the relay, hash-chained and signed per event;
3
+ * sender keys for message bodies; pairwise sealed key shares; a person's `self` conversation; and the person's
4
+ * context rules for their agents. Every object is strict: an unknown member fails the schema.
5
+ *
6
+ * sig = Ed25519(by.device, DOMAIN.convEvent + JCS(event without sig))
7
+ * h(0) = SHA-256(DOMAIN.convGenesis + JCS(cid))
8
+ * h(seq) = SHA-256(h(seq − 1) ‖ SHA-256(JCS(event))), over the raw 32-byte digests
9
+ * dm id = "d_" + base32lower(SHA-256(DOMAIN.dm + JCS([a, b] sorted)))[0..26]
10
+ * self id= "s_" + base32lower(SHA-256(DOMAIN.self + JCS(person)))[0..26]
11
+ *
12
+ * The authority rules over these shapes are `ConvLog.apply`'s (spec §16.7).
13
+ */
14
+ import { z } from "../../vendor/zod/index.js";
15
+ import { Message, TaskArtifactUpdateEvent, TaskStatusUpdateEvent, Part } from "./a2a.js";
16
+ import { Base64Url, ChannelName, EncKey, Hash, Key32, LIMITS, MachineId, Millis, PersonId, PROTOCOL, SessionName, Ulid } from "./common.js";
17
+ import { DelegationChain, DelegationGrant } from "./delegation.js";
18
+ import { RealmId } from "./realm.js";
19
+ // ---- identifiers (spec §16.1) ----
20
+ /** A person, or one agent of a person (`person/agent`). Every agent belongs to one person. */
21
+ export const ParticipantId = z
22
+ .string()
23
+ .regex(/^(?:[a-z][a-z0-9-]{0,31}|p_[a-z2-7]{26})(?:\/[a-z0-9][a-z0-9._-]{0,63})?$/, "person or person/agent");
24
+ /** `d_…` a dm (derived), `s_…` a person's `self` conversation (derived), `c_` + ULID a group or channel. */
25
+ export const ConvId = z.string().regex(/^(?:[ds]_[a-z2-7]{26}|c_[0-7][0-9A-HJKMNP-TV-Z]{25})$/, "conversation id");
26
+ export const ConvKind = z.enum(["dm", "group", "channel", "self"]);
27
+ /** Channels only; every other kind is private. */
28
+ export const Visibility = z.enum(["public", "private"]);
29
+ /** What a late joiner may read: `shared` gets earlier chain keys, `none` reads from its add onwards. */
30
+ export const HistoryPolicy = z.enum(["none", "shared"]);
31
+ export const ConvRole = z.enum(["owner", "admin", "member", "guest"]);
32
+ /** Who may do a thing in a group or channel. */
33
+ export const Permit = z.enum(["all", "admins"]);
34
+ /** Which mentions wake a seated agent: its own person's, any member's (under consent), or none. */
35
+ export const RespondTo = z.enum(["self", "members", "none"]);
36
+ /** A conversation's policy for members' agents mining it as context (spec §16.8). */
37
+ export const AgentContext = z.enum(["members", "seats", "none"]);
38
+ /** Why a sender epoch ends. */
39
+ export const RekeyCause = z.enum(["removed", "device", "added", "settings", "schedule"]);
40
+ const Seq = z.number().int().min(0);
41
+ const RetainDays = z.number().int().min(1).max(LIMITS.retainDaysMax);
42
+ /** A conversation event's signature: 64 bytes. */
43
+ const Sig = z.string().regex(/^[A-Za-z0-9_-]{86}$/, "Ed25519 signature, base64url");
44
+ /** An AES-GCM nonce: 12 bytes. */
45
+ const Nonce = z.string().regex(/^[A-Za-z0-9_-]{16}$/, "12-byte nonce, base64url");
46
+ const isAgent = (p) => p.includes("/");
47
+ // ---- ops (spec §16.2, "Ops") ----
48
+ /** A participant record as an op states it. `device` and `respondTo` are for agent participants only. */
49
+ export const Seat = z
50
+ .strictObject({ p: ParticipantId, role: ConvRole, device: MachineId.optional(), respondTo: RespondTo.optional() })
51
+ .refine((s) => isAgent(s.p) || (s.device === undefined && s.respondTo === undefined), { message: "device and respondTo are for agents only" });
52
+ export const ConvOp = z.discriminatedUnion("op", [
53
+ z.strictObject({
54
+ op: z.literal("create"),
55
+ kind: ConvKind,
56
+ visibility: Visibility.optional(),
57
+ history: HistoryPolicy,
58
+ retainDays: RetainDays,
59
+ /** A channel: the org it is open to when public. */
60
+ org: z.string().min(1).max(128).optional(),
61
+ participants: z.array(Seat).min(1).max(LIMITS.convParticipants),
62
+ /** Absent: `all`. */
63
+ post: Permit.optional(),
64
+ invite: Permit.optional(),
65
+ pins: Permit.optional(),
66
+ /** JCS(`ConvMeta`) sealed under the creator's epoch-0 message key 0 (spec §16.5). */
67
+ sealedMeta: Base64Url.max(2048).optional(),
68
+ }),
69
+ z.strictObject({ op: z.literal("add"), participants: z.array(Seat).min(1).max(LIMITS.convOpParticipants) }),
70
+ z.strictObject({ op: z.literal("accept") }),
71
+ z.strictObject({ op: z.literal("join") }),
72
+ z.strictObject({ op: z.literal("leave") }),
73
+ z.strictObject({ op: z.literal("remove"), participants: z.array(ParticipantId).min(1).max(LIMITS.convOpParticipants) }),
74
+ z.strictObject({ op: z.literal("role"), p: ParticipantId, role: ConvRole }),
75
+ z.strictObject({ op: z.literal("seat"), p: ParticipantId, device: MachineId.optional(), respondTo: RespondTo.optional() }),
76
+ z.strictObject({
77
+ op: z.literal("settings"),
78
+ visibility: Visibility.optional(),
79
+ history: HistoryPolicy.optional(),
80
+ retainDays: RetainDays.optional(),
81
+ post: Permit.optional(),
82
+ invite: Permit.optional(),
83
+ pins: Permit.optional(),
84
+ }),
85
+ z.strictObject({ op: z.literal("archive"), on: z.boolean() }),
86
+ z.strictObject({ op: z.literal("rekey"), epoch: z.number().int().min(1), cause: RekeyCause }),
87
+ ]);
88
+ /** The plaintext of `create.sealedMeta` and of a `meta` body's fields. */
89
+ export const ConvMeta = z.strictObject({
90
+ name: ChannelName.optional(),
91
+ topic: z.string().max(250).optional(),
92
+ purpose: z.string().max(250).optional(),
93
+ });
94
+ // ---- message bodies (spec §16.3) ----
95
+ export const Mention = z.union([
96
+ z.strictObject({ p: ParticipantId }),
97
+ /** Every participant person. Never wakes an agent. */
98
+ z.strictObject({ all: z.literal("channel") }),
99
+ /** Every participant person online now. Never wakes an agent. */
100
+ z.strictObject({ all: z.literal("here") }),
101
+ ]);
102
+ /** A file in the relay's blob store, sealed under its own AES-256-GCM key. The shape only; files land later. */
103
+ export const Attachment = z.strictObject({
104
+ blob: z.string().regex(/^b_[A-Za-z0-9_-]{43}$/, "blob id"),
105
+ key: Key32,
106
+ nonce: Nonce,
107
+ sha256: Hash,
108
+ bytes: z.number().int().positive().max(LIMITS.blobBytes),
109
+ mime: z.string().max(100),
110
+ name: z.string().max(255),
111
+ thumb: Base64Url.max(16_384).optional(),
112
+ });
113
+ // ---- linked channels (spec §16.10; reserved: validated, no daemon behaviour yet) ----
114
+ /** An outside channel a person may link as an alias of themselves. Telegram first, then Slack. */
115
+ export const LinkChannel = z.enum(["telegram", "slack"]);
116
+ /** What a linked channel may do: Jelly's `chat` and `view` action classes (spec §8.11), never more. */
117
+ export const LinkAuthority = z.enum(["chat", "view"]);
118
+ /** Who may mirror a conversation to a linked channel: nobody (the default), its owners and admins, or any member. */
119
+ export const BridgePolicy = z.enum(["none", "admins", "members"]);
120
+ /** A line's provenance when its person wrote it from a linked channel. Signed and sealed with the event. */
121
+ export const Via = z.strictObject({ channel: LinkChannel });
122
+ /**
123
+ * A person's linked channel, as a human-tier device records it in the person's `self` conversation (never the
124
+ * device log, which is public). `account` is the channel's own id for the person's account (Telegram `from.id`;
125
+ * Slack `team/user`); it exists only inside the sealed `self` conversation. The proof is the one-time code's digest
126
+ * and the six-digit code the person saw match on both sides. `revokedAt` ends it; the last writer wins by `seq`.
127
+ */
128
+ export const LinkRecord = z.strictObject({
129
+ id: Ulid,
130
+ channel: LinkChannel,
131
+ account: z.string().regex(/^[A-Za-z0-9._:/-]{1,128}$/, "channel account id"),
132
+ /** The person's device that runs the bridge and wrote this record. */
133
+ host: MachineId,
134
+ proof: z.strictObject({ method: z.literal("code-sas"), codeDigest: Hash, sas: z.string().regex(/^[0-9]{6}$/, "six digits") }),
135
+ authority: z
136
+ .array(LinkAuthority)
137
+ .min(1)
138
+ .max(2)
139
+ .refine((a) => new Set(a).size === a.length, { message: "each authority once" }),
140
+ linkedAt: Millis,
141
+ revokedAt: Millis.optional(),
142
+ });
143
+ /**
144
+ * Who can read a piece of content, for the audience guard: a person, or a linked channel's provider as
145
+ * `ext:<channel>:<link id>`. Not on the wire; the guard's reader sets are typed with it.
146
+ */
147
+ export const ReaderId = z.union([PersonId, z.string().regex(/^ext:(?:telegram|slack):[0-7][0-9A-HJKMNP-TV-Z]{25}$/, "ext:<channel>:<link id>")]);
148
+ export const ReaderSet = z.array(ReaderId).max(LIMITS.convParticipants + LIMITS.convParticipants);
149
+ export const ReceiptStage = z.enum(["delivered", "handed_to_agent", "read"]);
150
+ /**
151
+ * A task as a thread (spec §16.3): `request` is the thread root, from the requester to an agent participant;
152
+ * `status` and `artifact` come from that agent; `cancel` and `followUp` from the requester.
153
+ */
154
+ export const TaskEventBody = z.discriminatedUnion("k", [
155
+ z.strictObject({ k: z.literal("request"), to: ParticipantId.refine(isAgent, "a task goes to an agent"), message: Message, delegation: DelegationChain }),
156
+ z.strictObject({ k: z.literal("status"), root: Ulid, update: TaskStatusUpdateEvent }),
157
+ z.strictObject({ k: z.literal("artifact"), root: Ulid, update: TaskArtifactUpdateEvent }),
158
+ z.strictObject({ k: z.literal("cancel"), root: Ulid, reason: z.string().max(1000).optional() }),
159
+ z.strictObject({ k: z.literal("followUp"), root: Ulid, message: Message }),
160
+ ]);
161
+ export const ContextAccess = z.enum(["allow", "ask", "off"]);
162
+ export const ContextKind = z.enum(["own", "dm", "group", "channel.private", "channel.public"]);
163
+ export const ContextScope = z.union([z.strictObject({ cid: ConvId }), z.strictObject({ kind: ContextKind })]);
164
+ /** One of a person's rules for which of their agents may mine which conversations (spec §16.8). */
165
+ export const ContextRule = z.strictObject({
166
+ agent: z.union([SessionName, z.literal("*")]),
167
+ scope: ContextScope,
168
+ access: ContextAccess,
169
+ /** Absent: the conversation's retention. */
170
+ lookbackDays: RetainDays.optional(),
171
+ });
172
+ const scopeKey = (r) => `${r.agent} ${"cid" in r.scope ? `cid:${r.scope.cid}` : `kind:${r.scope.kind}`}`;
173
+ /** A person's whole rule set: at most one rule per (agent, scope). */
174
+ export const ContextRules = z
175
+ .array(ContextRule)
176
+ .max(LIMITS.contextRules)
177
+ .refine((rules) => new Set(rules.map(scopeKey)).size === rules.length, { message: "at most one rule per agent and scope" });
178
+ /** One sender chain at one index: `ck` is the chain key for message `idx` of `device`'s chain in `epoch`. */
179
+ export const KeyShare = z.strictObject({ epoch: Seq, device: MachineId, idx: Seq, ck: Key32 });
180
+ /** The plaintext of one recipient's sealed share in a `keys` event. */
181
+ export const KeySharePayload = z.strictObject({ shares: z.array(KeyShare).min(1).max(LIMITS.keyShares) });
182
+ /** The `self` conversation's bodies (spec §16.3, "The self conversation"). The last writer wins by `seq`. */
183
+ export const SyncBody = z.discriminatedUnion("s", [
184
+ z.strictObject({ s: z.literal("read"), cid: ConvId, upTo: Seq, thread: Ulid.optional() }),
185
+ z.strictObject({ s: z.literal("unread"), cid: ConvId, from: z.number().int().min(1) }),
186
+ z.strictObject({
187
+ s: z.literal("prefs"),
188
+ cid: ConvId,
189
+ notify: z.enum(["all", "mentions", "none"]),
190
+ muteUntil: Millis.optional(),
191
+ /** dms only; absent is off. */
192
+ receipts: z.boolean().optional(),
193
+ }),
194
+ z.strictObject({ s: z.literal("follow"), cid: ConvId, thread: Ulid, on: z.boolean() }),
195
+ z.strictObject({ s: z.literal("save"), cid: ConvId, target: Ulid, on: z.boolean() }),
196
+ z.strictObject({ s: z.literal("draft"), cid: ConvId, thread: Ulid.optional(), text: z.string().max(8000) }),
197
+ z.strictObject({ s: z.literal("joined"), cid: ConvId, on: z.boolean() }),
198
+ /** A consent grant (spec §6.9), verified with `verifyConsentGrant` over this raw value. */
199
+ z.strictObject({ s: z.literal("grant"), grant: z.record(z.string(), z.unknown()) }),
200
+ z.strictObject({ s: z.literal("context"), rules: ContextRules }),
201
+ z.strictObject({ s: z.literal("localRetention"), cid: ConvId, days: RetainDays }),
202
+ z.strictObject({ s: z.literal("keys"), cid: ConvId, shares: z.array(KeyShare).min(1).max(LIMITS.keyShares) }),
203
+ z.strictObject({ s: z.literal("link"), link: LinkRecord }),
204
+ ]);
205
+ /** The plaintext of a `msg` event. */
206
+ export const MsgBody = z.discriminatedUnion("t", [
207
+ z.strictObject({
208
+ t: z.literal("line"),
209
+ text: z.string().max(LIMITS.lineChars),
210
+ format: z.enum(["plain", "md"]),
211
+ /** The thread root's event id. */
212
+ thread: Ulid.optional(),
213
+ /** A thread reply also shown in the main view. */
214
+ broadcast: z.boolean().optional(),
215
+ mentions: z.array(Mention).max(LIMITS.mentions).optional(),
216
+ files: z.array(Attachment).max(LIMITS.files).optional(),
217
+ /** A2A data parts, rendered as cards. */
218
+ parts: z.array(Part).max(8).optional(),
219
+ /** The mention this line answers. */
220
+ answers: Ulid.optional(),
221
+ grants: z.array(DelegationGrant).max(LIMITS.agentMentions).optional(),
222
+ /** Written by its person from a linked channel. Never on an agent's line. */
223
+ via: Via.optional(),
224
+ }),
225
+ z.strictObject({ t: z.literal("edit"), target: Ulid, text: z.string().max(LIMITS.lineChars), mentions: z.array(Mention).max(LIMITS.mentions).optional() }),
226
+ z.strictObject({ t: z.literal("delete"), target: Ulid }),
227
+ z.strictObject({ t: z.literal("react"), target: Ulid, key: z.string().min(1).max(64), on: z.boolean() }),
228
+ z.strictObject({ t: z.literal("pin"), target: Ulid, on: z.boolean() }),
229
+ z.strictObject({ t: z.literal("task"), task: TaskEventBody }),
230
+ z.strictObject({ t: z.literal("receipt"), target: Ulid, stage: ReceiptStage }),
231
+ z.strictObject({
232
+ t: z.literal("meta"),
233
+ name: ChannelName.optional(),
234
+ topic: z.string().max(250).optional(),
235
+ purpose: z.string().max(250).optional(),
236
+ }),
237
+ z
238
+ .strictObject({ t: z.literal("policy"), agentContext: AgentContext.optional(), bridges: BridgePolicy.optional() })
239
+ .refine((p) => p.agentContext !== undefined || p.bridges !== undefined, { message: "a policy sets agentContext, bridges or both" }),
240
+ z.strictObject({ t: z.literal("sync"), sync: SyncBody }),
241
+ ]);
242
+ // ---- events and the log (spec §16.2) ----
243
+ const Position = z.strictObject({ seq: Seq, hash: Hash });
244
+ const header = {
245
+ v: z.literal(PROTOCOL),
246
+ realm: RealmId,
247
+ cid: ConvId,
248
+ /** Chosen by the author; unique in the conversation. */
249
+ id: Ulid,
250
+ by: z.strictObject({ person: PersonId, device: MachineId, agent: SessionName.optional() }),
251
+ ts: Millis,
252
+ /** The last op the author applied: its seq and h(seq), or {0, h(0)} before any. */
253
+ opHead: Position,
254
+ /** The head the author had, for gossip. */
255
+ seen: z.strictObject({ seq: z.number().int().min(1), hash: Hash }).optional(),
256
+ };
257
+ /** A control op, in plaintext: the relay routes and checks authority by it. */
258
+ export const ConvOpEvent = z.strictObject({ ...header, class: z.literal("op"), body: ConvOp, sig: Sig });
259
+ /** base64url(nonce ‖ AES-256-GCM ciphertext ‖ tag) of JCS(`MsgBody`), sealed under one message key. */
260
+ export const SealedBody = Base64Url.min(38).max(Math.ceil(((LIMITS.convPlaintextBytes + 28) * 4) / 3));
261
+ /** Everything else, sealed under the author device's sender key at (`epoch`, `idx`). */
262
+ export const ConvMsgEvent = z.strictObject({
263
+ ...header,
264
+ class: z.literal("msg"),
265
+ epoch: Seq,
266
+ idx: Seq,
267
+ /** Own-person wake hint only: sessions of `by.person` that this event may wake. */
268
+ wake: z.array(SessionName).min(1).max(LIMITS.wakeHints).optional(),
269
+ body: SealedBody,
270
+ sig: Sig,
271
+ });
272
+ /** One recipient device's share, sealed to it under the envelope seal (spec §5, "Sealing"). */
273
+ export const SealedShare = z.strictObject({
274
+ to: z.strictObject({ person: PersonId, device: MachineId }),
275
+ epk: EncKey,
276
+ nonce: Nonce,
277
+ ct: Base64Url.max(Math.ceil(((LIMITS.keyShares * 160 + 16) * 4) / 3)),
278
+ });
279
+ export const KeysBody = z.strictObject({
280
+ shares: z
281
+ .array(SealedShare)
282
+ .min(1)
283
+ .max(LIMITS.keySharesPerEvent)
284
+ .refine((shares) => new Set(shares.map((s) => s.to.device)).size === shares.length, { message: "one share per device" }),
285
+ });
286
+ /** Sender-key and history shares, sealed pairwise; the relay serves each share only to its recipient. */
287
+ export const ConvKeysEvent = z.strictObject({ ...header, class: z.literal("keys"), body: KeysBody, sig: Sig });
288
+ export const ConvEvent = z.discriminatedUnion("class", [ConvOpEvent, ConvMsgEvent, ConvKeysEvent]);
289
+ /** An event as the relay stores and serves it. The relay does not sign it; members verify the chain. */
290
+ export const ConvLogEntry = z.strictObject({ seq: z.number().int().min(1), prev: Hash, event: ConvEvent });
291
+ /** A log position: a seq and h(seq). */
292
+ export const ConvHead = Position;
@@ -28,6 +28,8 @@ export const ErrorCode = z.enum([
28
28
  "binding_invalid", // a device binding, log entry or its authority failed verification (hosted realms)
29
29
  "jelly_unavailable", // Jelly ID's key set or key history could not be fetched; never reported as invalid
30
30
  "log_conflict", // a device-log entry does not extend the log's head; resync and retry
31
+ "conv_conflict", // a conversation event does not extend the log, or its op head is not the current one; re-read and retry
32
+ "stale_epoch", // a conversation message is sealed under an epoch that is not the current one, or a rekey is due; re-seal and retry
31
33
  "device_limit", // the person already has LIMITS.devicesPerPerson current devices
32
34
  "admission_required", // dir.bind without a Jelly-vouched bind of the connecting device
33
35
  "admission_invalid", // dir.bind whose Jelly token is not live, or not for this directory's issuer and resource
@@ -42,8 +44,23 @@ export const ErrorCode = z.enum([
42
44
  "ticket_invalid", // deployment "jelly": the session ticket did not verify, expired, or names another session or agent
43
45
  "daemon_unavailable", // client could not reach the local daemon socket
44
46
  "daemon_mismatch", // the daemon on the socket is another version or IPC protocol than the client (spec §8.2)
47
+ "store_refused", // messagingd refused the home's store and changed nothing; StoreRefusedError.reason says why: pre-reset or newer (spec §8.8)
45
48
  "internal", // unexpected failure; details are logged locally, never sent
46
49
  ]);
50
+ /**
51
+ * The exit status of a messagingd or messaging-relay that refuses its store and changes nothing (spec §8.8): `EX_CONFIG`
52
+ * of sysexits(3), for either reason. messagingd also prints one stderr line,
53
+ * `messagingd: store_refused: <reason>: <why and how to start over>`. A client matches this status, the code and the
54
+ * reason, never the wording.
55
+ */
56
+ export const STORE_REFUSED_EXIT = 78;
57
+ /**
58
+ * Why a store is refused (spec §8.8):
59
+ * - `pre-reset`: it records no store generation, or another one. Starting over (moving the home aside) is the remedy.
60
+ * - `newer`: its `min_reader` is above this reader's schema: a newer messagingd wrote it. Upgrading is the remedy;
61
+ * moving the home aside would set a newer home aside.
62
+ */
63
+ export const StoreRefusedReason = z.enum(["pre-reset", "newer"]);
47
64
  export const ErrorBody = z.object({
48
65
  code: ErrorCode,
49
66
  message: z.string().max(500),
@@ -60,6 +77,28 @@ export class MessagingError extends Error {
60
77
  return { code: this.code, message: this.message.slice(0, 500) };
61
78
  }
62
79
  }
80
+ /** `store_refused`, with its reason as a field: clients branch on `reason`, never on the message. */
81
+ export class StoreRefusedError extends MessagingError {
82
+ reason;
83
+ constructor(reason, message, options) {
84
+ super("store_refused", message, options);
85
+ this.name = "StoreRefusedError";
86
+ this.reason = reason;
87
+ }
88
+ }
89
+ /** The stderr line of a messagingd that refuses its store: `messagingd: store_refused: <reason>: <text>`. */
90
+ export function storeRefusedLine(reason, text) {
91
+ return `messagingd: store_refused: ${reason}: ${text}`;
92
+ }
93
+ /**
94
+ * The reason on a messagingd refusal line, or undefined for any other line. Reads the tokens only; the text after
95
+ * them may change between releases.
96
+ */
97
+ export function storeRefusedReason(line) {
98
+ const match = /^messagingd: store_refused: ([a-z-]+): /.exec(line);
99
+ const parsed = StoreRefusedReason.safeParse(match?.[1]);
100
+ return parsed.success ? parsed.data : undefined;
101
+ }
63
102
  export function isMessagingError(value) {
64
103
  return value instanceof MessagingError;
65
104
  }
@@ -13,3 +13,4 @@ export * from "./directory-frames.js";
13
13
  export * from "./ipc.js";
14
14
  export * from "./ipc/device.js";
15
15
  export * from "./ipc/consent.js";
16
+ export * from "./conversation.js";
@@ -7,6 +7,7 @@ export { encodeTicket } from "./roster.js";
7
7
  export { grantHash } from "./delegation.js";
8
8
  export { signJellyToken } from "./directory/jelly-issuer.js";
9
9
  export { jellyHostDouble } from "./jelly-host-double.js";
10
+ export { sealConvMetaWith, sealConvMsgWith, sealKeySharesWith } from "./conversation/seal.js";
10
11
  /**
11
12
  * Narrows a result whose `kind` tells its shape (`item.read`, `conv.read`) to the expected kind, and
12
13
  * throws with both kinds named otherwise: `client.call("item.read", p).then(asKind("received"))`.
@@ -3,4 +3,4 @@
3
3
  * its IPC hello and a client compares it with its own (spec §8.2). A test keeps it equal to the
4
4
  * root package.json.
5
5
  */
6
- export const VERSION = "0.7.0";
6
+ export const VERSION = "0.7.1";