loopzero-gateway 0.0.0-stage → 0.1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,1074 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1
4
+
5
+ ### Minor Changes
6
+
7
+ - An inbound event may carry `images`, a list of the new `InboundImage`: media type, optional size and file name, and a `read()` that fetches the bytes on its first call. Nothing is downloaded until `read()` is called.
8
+
9
+ ## 0.33.0
10
+
11
+ ### Minor Changes
12
+
13
+ - d4c45f8: Widen the `loopzero-sdk` peer range to `>=4.62.0 <16` so `loopzero-host` installs with sdk 13 and 15. The gateway's tests and typecheck now run against `loopzero-sdk@15.0.0` and pass without source changes.
14
+
15
+ ## 0.32.0
16
+
17
+ ### Minor Changes
18
+
19
+ - c0a55b8: `MessageEvent` gains an optional `addressed` flag, set by these adapters on group and thread events whether or not `requireMention` is on, and `loopzero-gateway` adds `groupActivationHook({ mode, modeFor? })`, which blocks unaddressed group messages per chat.
20
+
21
+ ## 0.31.0
22
+
23
+ ### Minor Changes
24
+
25
+ - d7f5803: `configFromEnv` takes `{ prefix, rename, require, enabledBy }` (a string prefix still works), and a descriptor's `create(config, deps)` receives runtime dependencies from `ChannelEntry.deps`. The X descriptor reads `credentialStore`; the WhatsApp baileys variant reads `onQr` and `connectTimeoutMs`.
26
+
27
+ ## 0.30.0
28
+
29
+ ### Minor Changes
30
+
31
+ - 9dba293: `createAccessPolicyHook` takes an optional `messages` option (`pairingCode`, `invalidCode`, `failedSave`, `paired`, `pairingOff`) so an app can keep its own reply texts. Each entry defaults to the current wording.
32
+
33
+ ## 0.29.0
34
+
35
+ ### Minor Changes
36
+
37
+ - 4defb5a: `InboundAudio` is read on demand: `data` is replaced by `read(): Promise<Uint8Array>` and an optional `size`. The Telegram adapter downloads a voice note on the first `read()`, so a `pre_inbound` hook that blocks the message causes no download. `withMediaUnderstanding` reads the audio only when a transcriber is configured.
38
+ - 3bf9133: `reconnect: { retryFalse: true }` retries an adapter whose `connect()` answers `false`. A connect the runner abandoned (`connectTimeoutMs`) that rejects later is reported once through `onAdapterState` as `failed`. `runner.connected` is now a method, `runner.connected()`, returning the started adapters (it was a getter returning a set of platform names).
39
+ - dde3a3f: `scopedStrategy` accepts `keys` to override the `main` and linked-peer session keys, so apps with stored sessions can adopt it.
40
+
41
+ ## 0.28.1
42
+
43
+ ### Patch Changes
44
+
45
+ - 6d42c80: Widen the `loopzero-sdk` peer range to `>=4.62.0 <10` so npm admits SDK 6, 7, 8 and 9.
46
+
47
+ ## 0.28.0
48
+
49
+ ### Minor Changes
50
+
51
+ - 483b5d9: Add `JsonRpcLineClient`, `RpcOutcome`, `RpcNotification` and `JsonRpcChild`: a line-framed JSON-RPC client for a child process, keeping the error `data` member.
52
+ - 6ac37d3: Export `refuseUnsupportedAttachments` and add a protected `refuseAttachments` helper on `BasePlatformAdapter`, so an adapter no longer needs its own copy of the attachment refusal.
53
+ - e1f837c: Add `reportDiagnostic(tag, message, options?)` and `ReportDiagnosticOptions`: one place that redacts a diagnostic line and writes `[tag] message` to stderr. Every diagnostic line in core now goes through it, so a handler error that echoes a token is redacted in `BasePlatformAdapter.runHandler` and the Weixin connect failure too.
54
+ - c2e7954: Export `verifyHmac`, `verifyDigest`, `safeEqualString` and `DigestEncoding` for webhook signature checks, with secret rotation and constant-time comparison.
55
+
56
+ ### Patch Changes
57
+
58
+ - 6f73151: Remove the two package-local copies of the line-framed JSON-RPC client: `gateway-signal` and `gateway-imessage` now use the one `JsonRpcLineClient` exported by `loopzero-gateway`, so a single implementation exists. Raises their `loopzero-gateway` peer floor to `>=0.27.0`, the first core release that exports it.
59
+ - 03c3a2c: Use the core `JsonRpcLineClient` instead of a local copy, and raise the `loopzero-gateway` peer floor to 0.27.0.
60
+ - 776b2a8: `splitKeepingRows` decides whether a straddled table row fits a part by reading only that row, instead of walking `partLimit` units from the row's start first. With `unit: "codepoint"` that walk cost as much again as the cut itself on every part a row straddled, which put `gateway-nextcloud-talk`'s `splitForTalk` at 1.55x to 1.7x of the plain cut on a 1,000,000-character table in CI, past its 1.5x budget. The parts are the same.
61
+
62
+ ## 0.27.0
63
+
64
+ ### Minor Changes
65
+
66
+ - e3bf8c9: Add `jwksKeySet`, `decodeJwt` and `verifyRs256Jwt`: a JWKS key-set cache (max-age, shared in-flight read, unknown-kid refetch floor, stale-while-revalidate) and RS256 JWT signature verification for adapters whose platform signs requests with a JWT.
67
+
68
+ ### Patch Changes
69
+
70
+ - 8585427: README status lines say "0.x, pre-1.0" instead of a hard-coded version.
71
+
72
+ ## 0.26.0
73
+
74
+ ### Minor Changes
75
+
76
+ - f357dab: Export `ReconnectBackoff` and `ReconnectBackoffOptions` so adapters that hold a long-lived connection can share the runner's reconnect backoff, including a reset after a stable connection. `GatewayRunner` now uses it for its own retries.
77
+ - 770b67f: Type `SendResult.error` as `SendError` with shared `SendErrorCode` values, `retryAfterMs` and `platformCode`, and add `sendErrorFromHttp` to map an HTTP status to a `SendResult`.
78
+ - d7dbc27: `splitKeepingRows` takes an optional `{ unit: "utf16" | "codepoint" }` so `partLimit` can be measured in code points. `SplitKeepingRowsOptions` is exported.
79
+ - 28d3dd5: Add `createTokenCache` for expiring access tokens with one shared refresh, and use it in `WeixinAdapterBase`.
80
+
81
+ ## 0.25.0
82
+
83
+ ### Minor Changes
84
+
85
+ - a0b59f4: `ChannelWebhook.verify` may return a `Promise<boolean>`, and `createWebhookHandler` awaits it.
86
+
87
+ `ChannelWebhook.precheck` answers a request from its method, URL and headers before the body is read.
88
+
89
+ ## 0.24.0
90
+
91
+ ### Minor Changes
92
+
93
+ - 35d9d91: `channelConfigReaders` gains `readNumber` (a number or a digit string), `readBooleanString` (a boolean or `"true"`/`"false"`) and `readList` (an array or a comma-separated string), the string forms `configFromEnv` yields.
94
+
95
+ ## 0.22.1
96
+
97
+ ### Patch Changes
98
+
99
+ - b28c508: Raise the `loopzero-sdk` peer floor from `2.18.0` to `4.62.0`: `loopzero-sdk@2.18.0` publishes declarations that reference names it never defines, so a consumer at the old floor failed declaration checking (#584).
100
+
101
+ ## 0.22.0
102
+
103
+ ### Minor Changes
104
+
105
+ - 963a0ff: `loopzero-gateway` exports `channelConfigReaders(prefix)`, the config readers (`invalid`, `isAbsent`, `readString`, `requiredString`, `readBoolean`, `readFunction`) that channel packages each copied. `loopzero-gateway-line` uses them and raises its `loopzero-gateway` peer floor to `>=0.21.0`.
106
+ - 4e7c21b: Add `CredentialStore` and `createFileCredentialStore` to `loopzero-gateway`, and `credentialStore` / `credentialKey` to `XAdapterOptions` so a rotated X refresh token survives a restart.
107
+ - a12e04c: Raise the `loopzero-gateway` peer floor of `loopzero-gateway-x` to 0.20.0 and bump the workspace `loopzero-gateway` version to match.
108
+
109
+ ### Patch Changes
110
+
111
+ - 6c60bb6: Tidy the `configFromEnv` internals and cover more edge cases in its tests. No behaviour change.
112
+ - 2c0f560: `createChannels` now builds the environment variable names in its missing-config rejections with the same internal `envVarName` helper as `configFromEnv`, so both report the same full names.
113
+ - 8b46fb4: `createChannels` names the missing environment variable (with the optional `ChannelEntry.envPrefix`) instead of the config key in `missing_required_config` rejections.
114
+
115
+ ## 0.21.0
116
+
117
+ ### Minor Changes
118
+
119
+ - 6cad27f: Add `scopedStrategy` with four DM scopes (`main`, `per-peer`, `per-channel-peer`, `per-account-channel-peer`), peer links, an account label and a group scope.
120
+
121
+ ### Patch Changes
122
+
123
+ - 9b4ca9f: `createChannels` rejections for missing required config now name each field's environment variable; pass `envPrefix` on a `ChannelEntry` to match the prefix given to `configFromEnv`.
124
+
125
+ ## 0.20.0
126
+
127
+ ### Minor Changes
128
+
129
+ - 80bbb11: Add `createAccessPolicyHook`, `createFilePairingStore` and `senderKey`: a `pre_inbound` hook that lets owners, paired and allowlisted senders through on platforms that authenticate the sender, applies a DM policy (`pairing`, `allowlist`, `open`, `disabled`) to strangers, and rate limits refusals.
130
+ - 295d6fa: Add `configFromEnv` and `selectVariant`: bind channel config fields to environment variables (`ChannelConfigField.env`), collect secret values for log masking, and pick a descriptor variant.
131
+
132
+ ## 0.19.0
133
+
134
+ ### Minor Changes
135
+
136
+ - 9c832b2: Add `AdapterCapabilities` and `BasePlatformAdapter.capabilities` (edit, attachment kinds, typing, reactions, threads, max length), derived by default. Telegram reports `image` and `audio` attachments.
137
+ - 6a80cc5: Add `createAgentBindings` and `bindingStrategy`: rule-based choice of agent by platform, account and peer, with session keys prefixed by the bound agent.
138
+ - 8e54100: Add `parseChatCommand`, `commandHook` and `helpText`: one `pre_inbound` hook that strips a leading mention and `@bot` suffix, matches commands exactly and answers `/help`.
139
+ - 362e4ef: Add `createWebhookHandler`, a Fetch handler that routes every webhook channel, and `statusForDeliver`. `ChannelWebhook` gains optional `methods` and `handle`, and `WebhookRequest` gains `method` and `url`.
140
+ - 9f21ff7: `GatewayRunner` gains `connectTimeoutMs`, `onAdapterState` and `secrets` options (under `connectFailure: "isolate"`), an `adapter(platform)` lookup, a live `connected` set, and an exported `maskSecrets` helper and `AdapterState` type.
141
+ - 56bb1d8: Declare whether a channel's sender id is authenticated with `senderIdentity`.
142
+
143
+ ### Patch Changes
144
+
145
+ - e2a6da8: The cross-adapter lint tests no longer count `gateway-agent`, which bridges an agent to adapters and is not a platform adapter.
146
+
147
+ ## 0.18.0
148
+
149
+ ### Minor Changes
150
+
151
+ - 58aadd0: Add `withMediaUnderstanding`, a handler wrapper that folds a voice note's transcript into the turn text, naming any attachment it could not understand.
152
+
153
+ ## 0.17.0
154
+
155
+ ### Minor Changes
156
+
157
+ - 6329554: `rawBodyCapture` now refuses a body over 1 MiB with 413 when `maxBytes` is not given. The default is exported as `DEFAULT_WEBHOOK_MAX_BYTES`; pass `maxBytes: Number.POSITIVE_INFINITY` for no limit.
158
+
159
+ ## 0.16.1
160
+
161
+ ### Patch Changes
162
+
163
+ - f8ba934: Fix `defaultStrategy` giving two different senders the same session key. Ids that differed only by `-` versus `_` (sender, channel or topic) collided. Ids are now escaped (`_` to `__`, `-` to `_d`), so distinct ids always give distinct keys. Note: the session key of any existing session whose id contains `_` or `-` changes, so consumers with stored sessions may need a one-time migration.
164
+
165
+ ## 0.16.0
166
+
167
+ ### Minor Changes
168
+
169
+ - 6178f72: Make `qq` a first-party platform.
170
+
171
+ `loopzero-gateway` gains the `qq` key in `PlatformEventRegistry`, the `QQMessageEvent` type and a
172
+ `channelRendering` row (`plain`, markers removed). `PlatformName` grows by one member. Code that
173
+ lists every platform in a `Record<PlatformName, …>` or in a switch with a `never` default must add
174
+ it.
175
+
176
+ - 971efb1: Make `x` a first-party platform.
177
+
178
+ `loopzero-gateway` gains the `x` key in `PlatformEventRegistry`, the `XMessageEvent` and
179
+ `XThreadTweet` types and a `channelRendering` row (`plain`, markers removed). `PlatformName` grows
180
+ by one member. Code that lists every platform in a `Record<PlatformName, …>` or in a switch with a
181
+ `never` default must add it.
182
+
183
+ ### Patch Changes
184
+
185
+ - c6ee490: Restructure the QQ adapter and write the credential-shape and platform tables as rows, so they no longer repeat the same structure entry after entry. Behaviour and exports are unchanged.
186
+
187
+ ## 0.15.0
188
+
189
+ ### Minor Changes
190
+
191
+ - 00af16f: `BasePlatformAdapter` gains `react(channelId, messageId, emoji)`, which adds an emoji reaction to an inbound message. The default resolves `react_unsupported`; the Discord, Slack, Telegram and Matrix adapters implement it.
192
+ - db894a4: Make `raft` a first-party platform.
193
+
194
+ `loopzero-gateway` gains the `raft` key in `PlatformEventRegistry`, the `RaftMessageEvent` type
195
+ and a `channelRendering` row (`plain`, markers removed). `PlatformName` grows by one member. Code
196
+ that lists every platform in a `Record<PlatformName, …>` or in a switch with a `never` default must
197
+ add it.
198
+
199
+ - 3efe7e7: Make `wechat` a first-party platform.
200
+
201
+ `loopzero-gateway` gains the `wechat` key in `PlatformEventRegistry`, the `WeChatMessageEvent` type
202
+ and a `channelRendering` row (`plain`, markers removed). `PlatformName` grows by one member. Code
203
+ that lists every platform in a `Record<PlatformName, …>` or in a switch with a `never` default must
204
+ add it.
205
+
206
+ - 5980e00: Make `wecom` a first-party platform.
207
+
208
+ `loopzero-gateway` gains the `wecom` key in `PlatformEventRegistry`, the `WeComMessageEvent` type
209
+ and a `channelRendering` row (`plain`, markers removed). `PlatformName` grows by one member. Code
210
+ that lists every platform in a `Record<PlatformName, …>` or in a switch with a `never` default must
211
+ add it.
212
+
213
+ - d7ed3ab: Make `yuanbao` a first-party platform.
214
+
215
+ `loopzero-gateway` gains the `yuanbao` key in `PlatformEventRegistry`, the `YuanbaoMessageEvent`
216
+ type and a `channelRendering` row (`plain`, markers removed). `PlatformName` grows by one member.
217
+ Code that lists every platform in a `Record<PlatformName, …>` or in a switch with a `never`
218
+ default must add it.
219
+
220
+ - 6555723: Make `zalo` a first-party platform.
221
+
222
+ `loopzero-gateway` gains the `zalo` key in `PlatformEventRegistry`, the `ZaloMessageEvent` type and
223
+ a `channelRendering` row (`plain`, markers removed). `PlatformName` grows by one member. Code that
224
+ lists every platform in a `Record<PlatformName, …>` or in a switch with a `never` default must add
225
+ it.
226
+
227
+ - 00733b8: `loopzero-gateway` exports `WeixinAdapterBase` and `parseFlatXml`: the token, send and dispatch flow and the XML reader that the WeChat and WeCom adapters used to carry a copy each. The WeChat and WeCom adapters now extend the base.
228
+
229
+ ### Patch Changes
230
+
231
+ - bac158b: Keep the outbound checks and the inbound handler wiring in `BasePlatformAdapter`.
232
+
233
+ `BasePlatformAdapter` gains protected `refuseUnsendable`, `outboundText`, `subscribe`, `deliverInbound`
234
+ and `dispatchOnce`, so the `empty_text`, `not_connected` and `invalid_channel` checks, the
235
+ markdown translation, the handler slot and the dedup-then-dispatch step exist once instead of in
236
+ the adapters. Every adapter answers the same codes and messages as before.
237
+
238
+ ## 0.14.0
239
+
240
+ ### Minor Changes
241
+
242
+ - 458c34c: Wire channels from descriptors, and keep the channels that connect when another cannot.
243
+
244
+ `loopzero-gateway` exports `createChannels` and the types `ChannelDescriptor`,
245
+ `ChannelConfigField`, `ChannelWebhook`, `WebhookRequest`, `IngestResult`, `ChannelEntry`,
246
+ `ChannelRejection` and `CreateChannelsResult`. `createChannels(entries)` builds an adapter per
247
+ entry and returns `{ adapters, rejected }`: an entry whose required field is absent, `null` or
248
+ `""` is rejected with a `GatewayConfigurationError` coded `missing_required_config` naming the
249
+ keys, and a configuration error thrown by the descriptor's `create` is rejected the same way. Any
250
+ other error propagates. It connects nothing and makes no network call.
251
+
252
+ `GatewayRunner` accepts `connectFailure: "rollback" | "isolate"` (exported as `ConnectFailure`),
253
+ and `StartResult` is exported.
254
+ The default, `"rollback"`, is unchanged: one failed connect disconnects the adapters that did
255
+ connect and rejects `start()`. Under `"isolate"`, `start()` connects every adapter, wires inbound
256
+ only for the ones that connected, and reports the rest with a redacted reason.
257
+
258
+ `start()` now resolves a `StartResult` (`{ connected, failed }`) instead of `void`, under both
259
+ values. This is a type change: code that awaits `start()` and ignores the value is unaffected,
260
+ but a structural type declaring `start(): Promise<void>` that a `GatewayRunner` is assigned to
261
+ fails with TS2322, and a subclass overriding `start()` with that signature fails with TS2416.
262
+
263
+ `loopzero-gateway-telegram` exports `telegramChannel`, a socket channel whose config has a
264
+ required, secret `token` and an optional `allowedUsers`, and a `ConfigurationError` (a
265
+ `GatewayConfigurationError` with the `gateway-telegram` prefix). Called directly,
266
+ `telegramChannel.create` refuses a token that is not a string or is empty, and an `allowedUsers`
267
+ that is not an array of strings; through `createChannels`, an absent or empty token is rejected
268
+ first, as `missing_required_config`.
269
+
270
+ `loopzero-gateway-line` exports `lineChannel`, a webhook channel whose `webhook.verify` checks the
271
+ `x-line-signature` header against the raw body and whose `webhook.ingest` dispatches a verified
272
+ payload through `dispatchWebhookBody`, so a reply uses the cached reply token, or answers
273
+ `"malformed"` without dispatching. It answers `"no_handler"` (a member of `IngestResult`) when the
274
+ payload holds a text message for the handler and none is subscribed: before the runner started,
275
+ after it stopped, or when LINE's connect failed under `"isolate"`. Before, such a request answered
276
+ `"delivered"`, a route acknowledged it, and LINE did not redeliver the lost message.
277
+ `lineChannel.create` checks field types before the adapter's constructor.
278
+
279
+ `LineAdapter.dispatchWebhookBody` now resolves `"ok" | "no_handler"` instead of `void`. It answers
280
+ `"no_handler"`, dispatching nothing and caching no reply token, for a batch holding a text message
281
+ that passes the mention guard while no handler is subscribed; an empty or follow-only batch still
282
+ answers `"ok"`. It reads the handler once per batch, so a handler that unsubscribes while handling
283
+ one event still receives the rest of the batch. Code that ignores the value is unaffected; a
284
+ subclass overriding the method with `Promise<void>` fails with TS2416. `createWebhookServer` is
285
+ unchanged and still answers 200 before it dispatches.
286
+
287
+ Both descriptors are typed locally and import nothing `loopzero-gateway` 0.9.0 lacks, so the peer
288
+ range stays `>=0.9.0 <1.0.0`.
289
+
290
+ - e009dc3: Pair each platform with the rendering `ChatPresenter` needs.
291
+
292
+ `loopzero-gateway` exports `channelRendering(platform)` and the type `ChannelRendering`, a
293
+ `{ translate, format }` pair to spread into `loopzero-presenter`'s `ChatPresenter` options.
294
+ whatsapp and slack get single-character emphasis (`*bold*`, `_italic_`, `~strike~`), discord,
295
+ mattermost and teams keep markdown, and telegram, matrix, email, line and sms get the four inline
296
+ markers removed with `format: "plain"`. Before this, the presenter's defaults put `**bold**` on
297
+ the wire as characters on matrix and email, and handed telegram and slack a bold spelled for
298
+ another dialect.
299
+
300
+ Only bold, italic, strikethrough and inline code are translated. Headings, links, lists and block
301
+ quotes pass through, and fenced code blocks are not handled yet: the inline-code rule rewrites
302
+ their backticks. A platform the table does not know throws a `RangeError`. `toDialect` is
303
+ unchanged, and `loopzero-gateway` still does not depend on `loopzero-presenter`.
304
+
305
+ - 67e0b78: Make `nostr`, `feishu_lark`, `synology_chat`, `tlon_urbit` and `twitch` first-party platforms.
306
+
307
+ `loopzero-gateway` gains the five keys in `PlatformEventRegistry`, the `NostrMessageEvent`,
308
+ `FeishuLarkMessageEvent`, `SynologyChatMessageEvent`, `TlonUrbitMessageEvent` and
309
+ `TwitchMessageEvent` types, and a `channelRendering` row for each (`plain`, markers removed).
310
+ `PlatformName` grows by five members. Code that lists every platform in a
311
+ `Record<PlatformName, …>` or in a switch with a `never` default must add the five, and a package
312
+ that registered one of these keys through module augmentation now collides with the first-party
313
+ one (TS2717) and should drop it. The ten event types added since 0.11.0 are now declared in one
314
+ module beside the registry; every name is still exported from the package entry as before.
315
+
316
+ - 3f1788d: Send an image from a gateway handler, and refuse it wherever a platform cannot show one.
317
+
318
+ `loopzero-gateway` exports `OutboundAttachment` (`kind: "image"`, `mediaType`, `data`, optional
319
+ `filename`). `OutboundMessage` gains an optional `attachments` list, `ctx.reply(text, { attachments })`
320
+ carries it to the adapter (an empty list is left out), and `BasePlatformAdapter` declares
321
+ `supportsAttachments`, `false` by default. `DeliveryRouter.send` takes the same `attachments`
322
+ field. The runner and the router refuse an outbound carrying attachments as
323
+ `attachments_unsupported`, with no `sendMessage` call, when the adapter does not declare
324
+ `supportsAttachments`.
325
+
326
+ `loopzero-gateway-telegram` reports `supportsAttachments: true` and sends each image through
327
+ `sendPhoto`, the text as the first photo's caption up to 1024 UTF-16 units and after the photos
328
+ when longer. A non-image kind is refused as `attachments_unsupported`; a missing image, more
329
+ than 10 images or an image over 10 MiB as `invalid_attachment`; all with no request.
330
+
331
+ Every other adapter, and every adapter's `editMessage`, refuses an outbound carrying attachments
332
+ with `attachments_unsupported` and makes no platform call, instead of sending the text and
333
+ dropping the image.
334
+
335
+ The runner's auto-reply to a blocking `pre_inbound` hook no longer discards a `sendMessage` that
336
+ throws: the error reaches the `on_error` hooks with the event and is written to stderr, redacted,
337
+ as a handler error is. Dispatch still does not throw.
338
+
339
+ - 782e448: Carry voice in both directions. The inbound event gains an optional `audio` field, an
340
+ `InboundAudio` with the voice note's bytes, media type and duration in seconds, and
341
+ `OutboundAttachment` gains an `audio` member beside `image`. The Telegram adapter reads a polled
342
+ voice note through `getFile` and a download bounded at 20 MiB and 30 seconds, delivering the
343
+ message without `audio` and one stderr line when it cannot, and sends an audio attachment through
344
+ `sendVoice` with the reply text as its caption. Every other adapter refuses audio as it refuses an
345
+ image. Code that switches exhaustively on `OutboundAttachment["kind"]` gains a case.
346
+ - 48b1b04: Make `buzz` a first-party platform.
347
+
348
+ `loopzero-gateway` gains the `buzz` key in `PlatformEventRegistry`, the `BuzzMessageEvent`
349
+ type and a `channelRendering` row (`plain`, markers removed). `PlatformName` grows by one member.
350
+ Code that lists every platform in a `Record<PlatformName, …>` or in a switch with a `never` default
351
+ must add it.
352
+
353
+ - 1b27d5d: Make `clickclack` a first-party platform.
354
+
355
+ `loopzero-gateway` gains the `clickclack` key in `PlatformEventRegistry`, the `ClickClackMessageEvent`
356
+ type and a `channelRendering` row (`plain`, markers removed). `PlatformName` grows by one member.
357
+ Code that lists every platform in a `Record<PlatformName, …>` or in a switch with a `never` default
358
+ must add it.
359
+
360
+ - baadf93: Make `zalo_personal` a first-party platform.
361
+
362
+ `loopzero-gateway` gains the `zalo_personal` key in `PlatformEventRegistry`, the
363
+ `ZaloPersonalMessageEvent` type and a `channelRendering` row (`plain`, markers removed).
364
+ `PlatformName` grows by one member. Code that lists every platform in a `Record<PlatformName, …>`
365
+ or in a switch with a `never` default must add it.
366
+
367
+ - e980fb8: `loopzero-gateway` exports `SeenIds` (a bounded set of delivered ids) and `splitKeepingRows` (a
368
+ grapheme-safe split that keeps Markdown table rows whole). The SMS and LINE adapters import
369
+ `splitKeepingRows` instead of carrying copies; their peer floor is now `>=0.13.0`.
370
+ - 17c0713: Keep Markdown table rows whole when Discord, Slack, Teams, Telegram, WhatsApp and Mattermost split a long reply. A cut that fell inside a table row now moves back to the start of that row when the row fits in a part, so each row reaches the platform byte-identical. `chunkText` gains the opt-in `keepTableRows` option; text with no table row splits into the same chunks as before.
371
+
372
+ ### Patch Changes
373
+
374
+ - e9be726: Keep Markdown table rows intact through translation and splitting.
375
+
376
+ `channelRendering(platform).translate` and `toDialect` now rewrite a table row (a line whose first
377
+ non-blank character is `|`) one cell at a time. Before, an emphasis span could open in one cell
378
+ and close in the next, so `| 2 x *a | b* y |` lost both stars on the ten platforms that rewrite
379
+ markers. Text where no span crosses a row's pipe translates exactly as before. A lone `\r` counts
380
+ as a line ending, as in GFM. Inline code that holds an unescaped pipe inside a row is split at
381
+ that pipe, as GFM splits the cell, so its backticks no longer pair and the platforms that strip
382
+ markers now keep them.
383
+
384
+ `splitForLine` and `splitForSMS` no longer cut a table row in two at a part
385
+ boundary. When a cut would fall inside a row that fits in one part, the part ends before that row
386
+ and the row starts the next part. A row longer than a part is still cut by length. Every
387
+ character is kept, and every part stays within its limit (with the `(i/N) ` prefix counted on
388
+ SMS, whose numbering follows the new part count) except a single grapheme longer than the limit,
389
+ which is emitted whole as its own part, as before. Text with no table row splits exactly as
390
+ before. Two rows that each fill a part exactly arrive as three parts, the second holding only the
391
+ line ending between them.
392
+
393
+ No export, signature, dependency or peer range changes.
394
+
395
+ ## 0.12.0
396
+
397
+ ### Minor Changes
398
+
399
+ - 05e7fdd: Edit a message an adapter sent, so a reply can stream as a preview that the final text replaces.
400
+
401
+ `BasePlatformAdapter` gains `supportsEdit` (`false` by default) and
402
+ `editMessage(messageId, out)`, whose default refuses with `edit_unsupported`, makes no platform
403
+ call and never throws. A third-party subclass that already declares a member with either name and
404
+ a different type no longer compiles against this release, and under `noImplicitOverride` one
405
+ that declares it without `override` does not either.
406
+
407
+ Telegram (`editMessageText`), Discord (one REST `PATCH` of the message, without fetching the
408
+ channel), Slack (`chat.update`), Mattermost (`patchPost`), Matrix (an `m.replace` event) and Teams
409
+ (`updateActivity`, or `activities(conversationId).update` on `@microsoft/teams.api` below 2.0.14)
410
+ set `supportsEdit` to `true` and replace the text of a message they sent, honouring `format` as
411
+ `sendMessage` does (Slack's `chat.update` takes no `mrkdwn` argument, so its edit sends the text
412
+ as it is for every format), and return `{ ok: true, messageId }` with the same id. E-mail, SMS, LINE and
413
+ WhatsApp keep the default.
414
+
415
+ An edit is refused with no request as `edit_too_long` when the text would need more than one
416
+ platform message (Matrix has no length check), as `invalid_message_id` for an empty id (and on
417
+ Telegram one that is not a safe positive integer), and as `empty_text` and `not_connected` where
418
+ `sendMessage` answers those. Telegram answers its "message is not modified" refusal as a success.
419
+ On Discord an unknown channel is answered by the platform, as `discord_10003`. On Matrix a
420
+ `#alias` the adapter never resolved costs one lookup before the edit. Teams and Matrix do not
421
+ retry a refused markup as plain text on an edit, as they do on a send.
422
+
423
+ The six adapters keep `>=0.9.0` as their peer range on `loopzero-gateway` in this release. At run
424
+ time they work against any core in that range, since no adapter calls the base `editMessage`. Their
425
+ sources declare both members with `override`, so building them against a core older than this one
426
+ reports TS4113. The floor rises to this core in the next release, once it is on npm
427
+ (`docs/adr/0008-edit-capable-adapters-raise-their-core-floor-after-the-core-ships.md`). A
428
+ consumer's own typecheck reads the published declarations, which carry no `override`, and passes
429
+ on an older core.
430
+
431
+ - e646038: Make `google_chat` a first-party platform.
432
+
433
+ `loopzero-gateway` gains the `google_chat` key in `PlatformEventRegistry`, the
434
+ `GoogleChatMessageEvent` type, and a `channelRendering("google_chat")` row. `PlatformName` grows by
435
+ one member. Code that lists every platform in a `Record<PlatformName, …>` or in a switch with a
436
+ `never` default must add a `google_chat` entry, and a package that registered its own `google_chat`
437
+ key through module augmentation now collides with the first-party one (TS2717) and should drop it.
438
+
439
+ - e646038: Make `imessage` a first-party platform.
440
+
441
+ `loopzero-gateway` gains the `imessage` key in `PlatformEventRegistry`, the `IMessageMessageEvent`
442
+ type, and a `channelRendering("imessage")` row (`plain`, markers removed). `PlatformName` grows by
443
+ one member. Code that lists every platform in a `Record<PlatformName, …>` or in a switch with a
444
+ `never` default must add an `imessage` entry, and a package that registered its own `imessage` key
445
+ through module augmentation now collides with the first-party one (TS2717) and should drop it.
446
+
447
+ - e646038: Make `irc` a first-party platform.
448
+
449
+ `loopzero-gateway` gains the `irc` key in `PlatformEventRegistry`, the `IrcMessageEvent` type,
450
+ and a `channelRendering("irc")` row (`plain`, markers removed). `PlatformName` grows by one
451
+ member. Code that lists every platform in a `Record<PlatformName, …>` or in a switch with a
452
+ `never` default must add an `irc` entry, and a package that registered its own `irc` key through
453
+ module augmentation now collides with the first-party one (TS2717) and should drop it.
454
+
455
+ - e646038: Make `nextcloud_talk` a first-party platform.
456
+
457
+ `loopzero-gateway` gains the `nextcloud_talk` key in `PlatformEventRegistry`, the
458
+ `NextcloudTalkMessageEvent` type, and a `channelRendering("nextcloud_talk")` row (`markdown`,
459
+ passed through). `PlatformName` grows by one member. Code that lists every platform in a
460
+ `Record<PlatformName, …>` or in a switch with a `never` default must add a `nextcloud_talk`
461
+ entry, and a package that registered its own `nextcloud_talk` key through module augmentation now
462
+ collides with the first-party one (TS2717) and should drop it.
463
+
464
+ - e646038: Make `signal` a first-party platform.
465
+
466
+ `loopzero-gateway` gains the `signal` key in `PlatformEventRegistry`, the `SignalMessageEvent`
467
+ type, and a `channelRendering("signal")` row (`markdown`, text unchanged). `PlatformName` grows by
468
+ one member. Code that lists every platform in a `Record<PlatformName, …>` or in a switch with a
469
+ `never` default must add a `signal` entry, and a package that registered its own `signal` key
470
+ through module augmentation now collides with the first-party one (TS2717) and should drop it.
471
+
472
+ - b0b29d3: `rawBodyCapture(tag, { maxBytes })` refuses a body larger than `maxBytes` bytes before holding it.
473
+ A declared `content-length` over the limit is refused before any byte is kept; a streamed body is
474
+ refused once it passes the limit. Either way the rest of the stream is dropped, and when it ends
475
+ the middleware answers 413 with the JSON body `{ "error": "request body too large" }` and one
476
+ stderr line naming the router. `next` is not called, so no error reaches Express's final handler,
477
+ which would answer with an HTML page carrying the stack outside production. The middleware
478
+ answers once: data, the end of the stream or a stream error after a refusal do nothing. A
479
+ `maxBytes` that is not a finite number of zero or more throws a `RangeError` when the middleware is
480
+ built. Without the option the middleware keeps no limit, as before. `RawBodyCaptureOptions` is
481
+ exported.
482
+
483
+ ### Patch Changes
484
+
485
+ - d3f359a: `createChannels` builds one adapter per platform. In 0.11.0 it built every entry, so two entries
486
+ for one platform gave a `GatewayRunner` two adapters of that platform: the runner sent the first
487
+ one's replies through the second and never disconnected the first. A later entry for a platform
488
+ it already built is now rejected with a `GatewayConfigurationError` coded `duplicate_channel`, and
489
+ its `create` is not called. If your app lists two entries for one platform, the second one now
490
+ lands in `rejected` instead of being built. The first entry built for a platform wins, and an
491
+ entry rejected for its configuration does not claim its platform.
492
+
493
+ An entry whose `create` returns an adapter reporting another platform than its descriptor declares
494
+ is rejected with the code `platform_mismatch`, and the adapter it built is dropped unconnected.
495
+ The runner keys adapters by the adapter's own platform, so such an adapter would otherwise reach
496
+ it as a second adapter for a platform the duplicate check never saw.
497
+
498
+ - 7bea3d4: Two overlapping `start()` calls on one `GatewayRunner` now share one connect. A call made while
499
+ the first is still connecting no longer connects every adapter again; both calls resolve the same
500
+ `StartResult`, or reject with the same error. A start that rejects is not remembered, so a later
501
+ `start()` connects again.
502
+
503
+ A `stop()` during an in-flight `start()` no longer leaves an adapter connected on a stopped runner.
504
+ The start disconnects what connected, wires no inbound dispatch, and resolves
505
+ `{ connected: [], failed }` instead of naming the platforms it connected. Under `"rollback"`, a
506
+ connect that fails still rejects it.
507
+
508
+ Under the default `connectFailure: "rollback"`, the rollback waits for every connect to settle, so
509
+ an adapter that connects after another refused is disconnected as well. The rejection therefore
510
+ comes only once the slowest connect settles. With one adapter refusing and another whose connect
511
+ hangs, `start()` used to reject at once and now stays pending, as a successful rollback start and
512
+ an `"isolate"` start already did.
513
+
514
+ When `stop()`, a rollback, or a start that `stop()` overtook disconnects an adapter and that
515
+ `disconnect()` fails, the runner now writes one line to stderr naming the platform, with any
516
+ credential in the error redacted. The failure used to be discarded, so an adapter that might still
517
+ hold its platform session left no trace. How `start()` and `stop()` resolve or reject is unchanged.
518
+
519
+ - 9a8b81b: `listenerLifecycle(...).start()` rejects with the bind error when the port is taken, instead of
520
+ resolving over no listener. Under Express 5 the error reached the `listen` callback, which ignored
521
+ it, so a second server on a port another one held reported itself started and answered nothing;
522
+ under Express 4 the error was emitted on the server with no listener attached. The
523
+ `createWebhookServer` of `loopzero-gateway-line` and `loopzero-gateway-sms` returns this lifecycle,
524
+ so their `start()` now rejects with `EADDRINUSE` in that case, and a later `start()` tries again.
525
+ `ListenableApp.listen` declares the error argument Express 5 passes, and `ListenerLike` the
526
+ optional `once("error")` Express 4's server has.
527
+
528
+ ## 0.11.0
529
+
530
+ ### Minor Changes
531
+
532
+ - 39d06f8: Wire channels from descriptors, and keep the channels that connect when another cannot.
533
+
534
+ `loopzero-gateway` exports `createChannels` and the types `ChannelDescriptor`,
535
+ `ChannelConfigField`, `ChannelWebhook`, `WebhookRequest`, `IngestResult`, `ChannelEntry`,
536
+ `ChannelRejection` and `CreateChannelsResult`. `createChannels(entries)` builds an adapter per
537
+ entry and returns `{ adapters, rejected }`: an entry whose required field is absent, `null` or
538
+ `""` is rejected with a `GatewayConfigurationError` coded `missing_required_config` naming the
539
+ keys, and a configuration error thrown by the descriptor's `create` is rejected the same way. Any
540
+ other error propagates. It connects nothing and makes no network call.
541
+
542
+ `GatewayRunner` accepts `connectFailure: "rollback" | "isolate"` (exported as `ConnectFailure`),
543
+ and `StartResult` is exported.
544
+ The default, `"rollback"`, is unchanged: one failed connect disconnects the adapters that did
545
+ connect and rejects `start()`. Under `"isolate"`, `start()` connects every adapter, wires inbound
546
+ only for the ones that connected, and reports the rest with a redacted reason.
547
+
548
+ `start()` now resolves a `StartResult` (`{ connected, failed }`) instead of `void`, under both
549
+ values. This is a type change: code that awaits `start()` and ignores the value is unaffected,
550
+ but a structural type declaring `start(): Promise<void>` that a `GatewayRunner` is assigned to
551
+ fails with TS2322, and a subclass overriding `start()` with that signature fails with TS2416.
552
+
553
+ `loopzero-gateway-telegram` exports `telegramChannel`, a socket channel whose config has a
554
+ required, secret `token` and an optional `allowedUsers`, and a `ConfigurationError` (a
555
+ `GatewayConfigurationError` with the `gateway-telegram` prefix). Called directly,
556
+ `telegramChannel.create` refuses a token that is not a string or is empty, and an `allowedUsers`
557
+ that is not an array of strings; through `createChannels`, an absent or empty token is rejected
558
+ first, as `missing_required_config`.
559
+
560
+ `loopzero-gateway-line` exports `lineChannel`, a webhook channel whose `webhook.verify` checks the
561
+ `x-line-signature` header against the raw body and whose `webhook.ingest` dispatches a verified
562
+ payload through `dispatchWebhookBody`, so a reply uses the cached reply token, or answers
563
+ `"malformed"` without dispatching. It answers `"no_handler"` (a member of `IngestResult`) when the
564
+ payload holds a text message for the handler and none is subscribed: before the runner started,
565
+ after it stopped, or when LINE's connect failed under `"isolate"`. Before, such a request answered
566
+ `"delivered"`, a route acknowledged it, and LINE did not redeliver the lost message.
567
+ `lineChannel.create` checks field types before the adapter's constructor.
568
+
569
+ `LineAdapter.dispatchWebhookBody` now resolves `"ok" | "no_handler"` instead of `void`. It answers
570
+ `"no_handler"`, dispatching nothing and caching no reply token, for a batch holding a text message
571
+ that passes the mention guard while no handler is subscribed; an empty or follow-only batch still
572
+ answers `"ok"`. It reads the handler once per batch, so a handler that unsubscribes while handling
573
+ one event still receives the rest of the batch. Code that ignores the value is unaffected; a
574
+ subclass overriding the method with `Promise<void>` fails with TS2416. `createWebhookServer` is
575
+ unchanged and still answers 200 before it dispatches.
576
+
577
+ Both descriptors are typed locally and import nothing `loopzero-gateway` 0.9.0 lacks, so the peer
578
+ range stays `>=0.9.0 <1.0.0`.
579
+
580
+ - e13abe8: Pair each platform with the rendering `ChatPresenter` needs.
581
+
582
+ `loopzero-gateway` exports `channelRendering(platform)` and the type `ChannelRendering`, a
583
+ `{ translate, format }` pair to spread into `loopzero-presenter`'s `ChatPresenter` options.
584
+ whatsapp and slack get single-character emphasis (`*bold*`, `_italic_`, `~strike~`), discord,
585
+ mattermost and teams keep markdown, and telegram, matrix, email, line and sms get the four inline
586
+ markers removed with `format: "plain"`. Before this, the presenter's defaults put `**bold**` on
587
+ the wire as characters on matrix and email, and handed telegram and slack a bold spelled for
588
+ another dialect.
589
+
590
+ Only bold, italic, strikethrough and inline code are translated. Headings, links, lists and block
591
+ quotes pass through, and fenced code blocks are not handled yet: the inline-code rule rewrites
592
+ their backticks. A platform the table does not know throws a `RangeError`. `toDialect` is
593
+ unchanged, and `loopzero-gateway` still does not depend on `loopzero-presenter`.
594
+
595
+ ## 0.10.0
596
+
597
+ ### Minor Changes
598
+
599
+ - 1754a0e: Add `toDialect(text, platform)` — markdown into the target channel's own dialect.
600
+
601
+ Measured across every `adapter.ts` and `split.ts` in the ten packages: no package transforms a
602
+ single character of text. What exists is markdown escape, HTML escape, phone normalisation and
603
+ post-cut newline cleanup. All ten READ `OutboundMessage.format`, but reading a flag is not
604
+ translating a body — so the agent answered `**Bom Sucesso (MG)**` and both LINE and WhatsApp
605
+ delivered the asterisks to a real phone.
606
+
607
+ The adapters refuse the translation deliberately and correctly: `gateway-whatsapp` reads `format`
608
+ only to warn once, because emphasis there is inline in the text rather than a transport flag. An
609
+ adapter is transport; translation depends on what was said AND where it is going, which makes it
610
+ presentation. It ships here as a pure function so the channel presenter in `loopzero` can call it
611
+ without `loopzero-gateway` ever depending on `loopzero-presenter` (B-019 FR-005 / AC-004).
612
+
613
+ Taught three dialects — WhatsApp (`*bold*`, `_em_`, `~strike~`), LINE and SMS (markers dropped, no
614
+ rich text). A platform it has not been taught passes through UNCHANGED: inventing a mapping is
615
+ wrong invisibly, passing `**bold**` through is wrong where somebody can see it.
616
+
617
+ - e05b146: The `loopzero-sdk` peer range admits the published `latest`. `>=2.18.0 <5` excluded `5.9.0`, so the
618
+ dependency gate counted this package among those a release would strand
619
+ (getloopscale/shared-workflows#64).
620
+
621
+ **Both ends were installed and run, not reasoned about:**
622
+
623
+ | sdk | typecheck | suite |
624
+ | ----------------------------------------------------------------- | --------- | ---------- |
625
+ | 2.18.0 — the declared floor, three majors below the devDependency | clean | 164 passed |
626
+ | 5.9.0 — the published latest | clean | 164 passed |
627
+
628
+ The floor is the surprise: `>=2.18.0` had never been exercised here — the devDependency was
629
+ `^4.62.0` — and it holds. This package makes one import from `loopzero-sdk`, and it has not moved
630
+ across three majors.
631
+
632
+ No code changed. A clean consumer install of the tarball with `loopzero-sdk@5.9.0` reports no
633
+ `ERESOLVE` and resolves one copy.
634
+
635
+ ## 0.9.0
636
+
637
+ ### Minor Changes
638
+
639
+ - b38172b: **The peer floor on `loopzero-gateway` rises with this release.** Every adapter now implements
640
+ `deliver` over `runHandler`, and neither exists in an older core — an adapter installed against one
641
+ does not build. `dep-check` caught that by building the whole workspace against the floor each
642
+ package claimed, which is the one thing a version range cannot tell you by reading it.
643
+
644
+ The floor is set in the version commit rather than here, because a range cannot name a version that
645
+ does not exist yet: raised in the workspace, the same gate then fails the other way round — every
646
+ adapter declaring a floor above the core installed beside it. That is the shape `fa70153` used when
647
+ these ranges were first written.
648
+
649
+ `deliver(event)` — every adapter can now be handed an event that arrived out of band (#83).
650
+
651
+ `onInbound` was the seam every adapter implemented and it had no public counterpart. Six platforms
652
+ self-deliver once connected — long polling, a gateway socket, Socket Mode, a sync loop, IMAP — so
653
+ the asymmetry stayed invisible: `GatewayRunner` worked for eight platforms and silently did nothing
654
+ for LINE and WhatsApp Cloud, whose payloads arrive on an HTTP route the application owns. Every app
655
+ wired those two by hand, beside the runner rather than through it.
656
+
657
+ ```ts
658
+ const outcome = await adapter.deliver(event); // "ok" | "no_handler" | "handler_threw"
659
+ ```
660
+
661
+ The three outcomes are distinguished because a caller acts on them differently: answering a webhook
662
+ 200 when nobody was subscribed tells the provider to stop retrying a message nothing received.
663
+
664
+ `BasePlatformAdapter.runHandler` holds the containment once, where ten copies of it used to live —
665
+ a handler is user code, its throw is named as the handler's failure rather than the platform's, and
666
+ delivery continues. Each adapter's `deliver` is one line over it.
667
+
668
+ Also: `gateway-sms`'s `createWebhookServer` now signs against the configured `publicUrl` (#90).
669
+ Twilio verifies against the URL it POSTed to, and behind a proxy that rewrites `host` — a tunnel, an
670
+ ingress, a load balancer terminating TLS — the reconstruction from headers yields the internal
671
+ address, so a correct signature fails on every delivery. `publicUrl` is required by all three
672
+ backend option shapes and documented as "used by signature verifier"; until now no source file read
673
+ it. The header reconstruction stays as the fallback for an app served directly.
674
+
675
+ - 4b1d4bb: The half of an Express webhook server that is the same everywhere now lives in one place (#89).
676
+
677
+ `gateway-line` and `gateway-sms` each shipped one and shared 101 of ~170 lines: the lazy `express`
678
+ load, the raw-body capture with the hang it documents, and the start/stop lifecycle. What differs —
679
+ signature verification, body parsing, routing — stayed where it belongs.
680
+
681
+ It had already been paid for. A write-once latch made `start()` after `stop()` return without
682
+ creating a listener, which is a port nothing answers on with no error and no log, and the fix had to
683
+ be applied to both files by one commit because the latch lived in the copied half.
684
+
685
+ `loopzero-gateway` now exports `loadPeer`, `rawBodyCapture` and `listenerLifecycle`. **This does not
686
+ make express a dependency of the core**: nothing in that module imports it. Every shape is
687
+ structural — a request is whatever has `readableEnded` and `on`, a listener is whatever has `listen`
688
+ and `close` — so the two packages that use express keep declaring it and the core never learns the
689
+ name.
690
+
691
+ Every adapter README now states how inbound reaches it (#91): a webhook the application must
692
+ authenticate, a WebSocket, a sync loop, or an SDK that owns its own HTTP server. The three that have
693
+ no webhook say so with the reason, because an absence that is a decision should not read as a gap.
694
+
695
+ - 348bc02: WhatsApp: send to the address that routes, and answer where the message came from (#82, #84).
696
+
697
+ **A send that WhatsApp discards no longer reports success.** Baileys hands back a
698
+ locally-generated `wamid` whether or not the JID routes anywhere, and the backend treated that id
699
+ as proof of delivery — so a message nobody received was recorded as a success by the caller's log,
700
+ its metrics and its retry logic. Measured on a real account: `5535998838687` and `553598838687` are
701
+ the same Brazilian line, both answered `ok: true`, and only the second arrived.
702
+
703
+ `send` now asks WhatsApp which form it routes to before sending, and refuses a number the server
704
+ does not know with `undeliverable` naming the number. That fixes the Brazilian ninth digit without a
705
+ Brazil-specific rule anywhere in this package — the answer is whatever the server says, for any
706
+ country. The lookup is cached for the life of the session, so it costs one round-trip per recipient.
707
+
708
+ **An inbound event now carries the address it arrived on**, as `whatsapp.channelJid`. `channel.id`
709
+ is normalised to digits — which is what an allowlist compares — and that normalisation strips the
710
+ domain, the part that says whether an address is a phone, a group, or an account's linked identity.
711
+ A note-to-self arrives addressed by LID, so replying to `channel.id` rebuilt `…@s.whatsapp.net`, an
712
+ address that does not exist.
713
+
714
+ **`send` accepts a qualified JID verbatim.** A `to` containing `@` is already an address and is
715
+ passed through untouched, where it used to become `231116569108705@lid@s.whatsapp.net`. So
716
+ answering an inbound event is now:
717
+
718
+ ```ts
719
+ await adapter.sendMessage({
720
+ channel: { id: event.whatsapp.channelJid ?? event.channel.id, type: "dm" },
721
+ text,
722
+ });
723
+ ```
724
+
725
+ Not affected: the Cloud backend. Meta rejects an unroutable recipient with an error code, so the
726
+ same mistake surfaces there instead of vanishing.
727
+
728
+ ## 0.8.0
729
+
730
+ ### Minor Changes
731
+
732
+ - 9729ab3: The redactor covers this domain's credentials, and says which it does not.
733
+
734
+ `Security.redact` ships patterns for AI and cloud provider keys. Measured across the sixteen
735
+ credential fields these ten adapters declare, it masked one: Slack's `xoxb-`, which is one of its
736
+ built-ins. On a Telegram token it was worse than absent — a token is `<bot_id>:<secret>`, the numeric
737
+ prefix is the bot's PUBLIC user id, and the SDK's `key=value` matcher stops at the colon, so
738
+ `token=8123456789:AAF…` came out as `token=***:AAF…`.
739
+
740
+ Six shapes with a distinctive structure — Telegram, Discord, Slack's app token, Matrix, WhatsApp,
741
+ Teams — are now replaced entirely before the text reaches the SDK. Entirely rather than the SDK's
742
+ `first6…last4`, because the six leading characters of a token identify the account it belongs to.
743
+
744
+ Ten fields are recorded as deliberately uncovered, each with its reason. 32 lowercase hex is also an
745
+ md5 digest and a dashless UUID; 26 lowercase alphanumerics is a ULID; a passphrase is
746
+ indistinguishable from prose. A pattern wide enough to catch those eats the correlation ids and
747
+ trace ids a developer reads an error log to find, and losing one costs a debugging session.
748
+
749
+ `redactSecrets` masks locally rather than registering with `Security.addPattern`. Registering did two
750
+ things wrong: the SDK applies extra patterns before its own `key=value` rule, so claiming a value
751
+ there DOWNGRADED `password=***` to `password=hunter…aple`; and it mutates module state inside the
752
+ SDK, so an app importing this package inherited these shapes in its own unrelated redaction.
753
+
754
+ New exports: `redactSecrets`, `maskShapes`, `CREDENTIAL_SHAPES`.
755
+
756
+ ## 0.7.1
757
+
758
+ ### Patch Changes
759
+
760
+ - 29e2e28: The seam between the three repositories is documented, and the reason given for one contract was corrected.
761
+
762
+ `loopzero-gateway`'s README — the npm page — now says which repository owns which half: LoopZero the
763
+ HTTP route and the signature check, these packages the translation of the payload it hands over, the
764
+ SDK one redaction helper. A `quality:integration-story` gate fails when that disappears and passes
765
+ when the prose is rewritten around the same facts.
766
+
767
+ Both adapters' published docblocks stated that a LoopZero app's `onMessage` runs AFTER the 200 is
768
+ answered, so a throw there had no status left to change. Measured against `loopzero@0.48.14`,
769
+ `handleChannelWebhook` awaits `onMessage` BEFORE building the response and catches nothing around
770
+ it: a throw means the 200 is never built, and mounted in a LoopZero route the rejection reaches that
771
+ route's error boundary and is answered 500 where the platform expected an acknowledgement. `parseInbound` returning `null`
772
+ is unchanged and still the right contract — only the stated reason was wrong, and it was reaching
773
+ users through the `.d.ts` on hover.
774
+
775
+ `loopzero-gateway-sms`'s docblocks also named the wrong seam. Its `parseInbound` is
776
+ `(options, ctx)`, and the `SignatureContext` it needs carries the raw body, the headers and the URL
777
+ — none of which LoopZero's `ChannelMessage` provides, so the signature check cannot be performed
778
+ from inside `onMessage` for any provider. SMS goes through its own `createWebhookServer`, and the
779
+ published `.d.ts` says so now instead of claiming to be the gateway half of the channel seam.
780
+
781
+ ## 0.7.0
782
+
783
+ ### Minor Changes
784
+
785
+ - 74a79b5: A gateway can now be authored, published and consumed outside this repository.
786
+
787
+ `PlatformName` and `MessageEvent` derive from a new exported `PlatformEventRegistry`, an interface
788
+ other packages extend through TypeScript declaration merging:
789
+
790
+ ```ts
791
+ declare module "loopzero-gateway" {
792
+ interface PlatformEventRegistry {
793
+ signal: SignalMessageEvent;
794
+ }
795
+ }
796
+ ```
797
+
798
+ Exhaustive narrowing survives, including over platforms the core has never heard of: forget a
799
+ `case` for a third-party platform and the build breaks, exactly as it does for the ten shipped
800
+ here. A misspelled platform name is still a compile error — the union is opened to extension, not
801
+ to arbitrary strings.
802
+
803
+ Both sides of an augmentation are gated. An entry typed `any`, registered under an index signature,
804
+ carrying a non-literal discriminator, or disagreeing with its own key is excluded rather than
805
+ admitted. Each of those was measured to break narrowing for **every** consumer before the guards
806
+ existed — an index signature made the whole union resolve to `never`, and an optional entry injected
807
+ `undefined` into it. Twelve augmentation shapes are compiled in CI against the published
808
+ declaration to keep it that way.
809
+
810
+ **Behaviour change:** `BaseMessageEvent.platform` is now `string` rather than `PlatformName`. Every
811
+ concrete variant still narrows it to its own literal, so code holding a `MessageEvent` is
812
+ unaffected. Code that assigns `.platform` off a bare `BaseMessageEvent` into a `PlatformName` slot
813
+ will need a narrowing step. This is required by the derivation: `PlatformName` now comes from the
814
+ guarded union, and naming it on the base would make the two reference each other.
815
+
816
+ See `docs/adr/0002-platform-event-registry.md`, which supersedes `docs/adr/0001-message-event-closed-union.md`.
817
+
818
+ ## 0.6.1
819
+
820
+ ### Patch Changes
821
+
822
+ - b631af7: **The integration bootstrap scripts now name reused container state as the cause.** Both create a server and then create accounts inside it, so both are idempotent only against a _fresh_ container. Run either against one that survived a previous run and it fails in a voice that does not name the cause — and Matrix's is actively misleading:
823
+
824
+ ```
825
+ matrix: register loopzero-bot failed: {… "error":"Invalid registration token"}
826
+ mattermost: create first user failed (400): An account with that username already exists.
827
+ ```
828
+
829
+ The token was read from the log and sent correctly. It is "invalid" only because the server consumed it at its first boot, so the message sends the reader hunting the one thing that is not wrong. Measured: two round-trips before the remedy — a `:down` — became obvious, and the remedy is one command.
830
+
831
+ Each failure now prints it, and only when the failure actually matches a reused-state signature. Attaching the advice to every failure would send someone to recreate a container over a network blip and would train them to skip the line, which is how a helpful message becomes noise.
832
+
833
+ The decision is a pure function with its own tests, kept out of both scripts: the scripts boot containers and call `process.exit`, so they are untestable by construction, and "is this reused state?" is the only part with a right answer.
834
+
835
+ - 58d302e: **A behavioural conformance suite now runs the `PlatformAdapter` contract against all nine credential-based adapters at once**, in `integration/tests/unit/`. It needs no credential and no network — every assertion is about what an adapter does _before_ it connects, because a conformance suite that needs provisioning is a conformance suite that does not run.
836
+
837
+ The existing cross-adapter gate reads source text, which is the right tool for what it catches and the wrong one for this. Getting that file honest took five attempts in this repository, four of which passed while checking nothing: a regex matching zero declarations, a window reaching into the neighbouring method and accepting its guard, a brace matcher fooled by a string literal, a floor that only fired when the count dropped. Each was a statement about text that read like a statement about behaviour.
838
+
839
+ What the new suite asserts, per adapter: it declares the platform it is (the routing key — an adapter naming itself wrong is silently unreachable rather than broken); `disconnect()` on one that never connected resolves rather than throwing, and again on a second call; and the unsubscribe `onInbound` returns is safe to call twice. All nine conform today, verified by mutation — a wrong `platform`, a throwing `disconnect()`, and an `off()` that throws on reuse each fail it.
840
+
841
+ One invariant is **deliberately absent and says so in the file**: "a stale unsubscribe does not deafen a live subscription". It was written, it passed, and mutation showed it could not fail — the only assertion available without a connection is that `onInbound` returns a function, which holds either way. It stays covered textually for all ten and behaviourally for WhatsApp, whose adapter takes a backend and therefore has a dispatch seam. A file arguing that behaviour beats text should not make the argument with an assertion that cannot fail.
842
+
843
+ ## 0.6.0
844
+
845
+ ### Minor Changes
846
+
847
+ - 08abaed: **`GatewayRunner.stop()` is now terminal, and says so instead of leaving a runner nothing can stop.**
848
+
849
+ `start()` and `stop()` were each written to be idempotent, but they guarded on different flags. `stop()` cleared `connected` and set `stopped`; nothing ever cleared `stopped`. So a second `start()` sailed past its `connected` guard, reconnected every adapter and rewired inbound dispatch — while the next `stop()` returned at its own `stopped` guard without disconnecting anything. Measured on the previous release: two connects, one disconnect, and a live inbound handler that no call could take down.
850
+
851
+ Nothing reported this. The adapters stayed connected, the events kept arriving, and both methods returned normally. A process that reloads configuration or reconnects after a network failure by restarting the runner leaked a connection every cycle.
852
+
853
+ `start()` on a stopped runner now throws `GatewayLifecycleError` with `code: "runner_stopped"`, and the message says to construct a new runner. That is the whole of the behaviour change: a call that previously appeared to succeed while corrupting state now fails at the call that cannot be honoured, which is the only point where a caller can still do something about it.
854
+
855
+ Adds `GatewayLifecycleError` and `GatewayLifecycleErrorOptions` to the public API. It is deliberately separate from `GatewayConfigurationError`: that one reports a bad setting, this one reports a fine setting used at an impossible moment.
856
+
857
+ - 66e08ba: **A third WhatsApp backend: `WhatsAppBaileysBackend`.** It speaks the WhatsApp Web multi-device protocol over a WebSocket. Where the `web` backend drives a headless Chromium through `whatsapp-web.js`, this holds a socket — that is the whole difference in kind.
858
+
859
+ Reach it with `WhatsAppAdapter.fromBaileys({ sessionDir })`, or through `WhatsAppAdapter.from({ backend: "baileys", baileys: { … } })` when the choice arrives as configuration rather than as a decision in code. `baileys` is an **optional peer dependency** (`>=7.0.0-rc14`), loaded lazily at connect: a consumer who never constructs this never needs it installed.
860
+
861
+ **Added rather than replacing**, for three reasons a substitution would not give. Nobody loses a paired session — a Puppeteer profile and a multi-file auth state are not interchangeable. The comparison against the incumbent becomes measurable rather than asserted, which is the whole point: no comparison has been made yet, and this changeset does not claim one. And retreat stays cheap, because nobody is forced onto it.
862
+
863
+ **Unofficial, and no amount of code changes that.** It automates a WhatsApp Web session, which Meta's terms do not sanction and which can get a number banned. Use a number created for this and nothing else, never a personal one.
864
+
865
+ Three decisions worth naming:
866
+
867
+ _Sends are serialised_ — one `sendMessage` in flight per socket, including when one times out. That last clause was not true when this was first written: the queue advanced on the raced result, and a timeout does not cancel a `sendMessage`, so a timed-out send stayed on the socket while the next one started — reaching the exact hazard the serialisation exists to prevent, through the timeout meant to bound it. A review found it; there is now a test that fails if the queue goes back to advancing on the race. Honest about provenance: both peer gateways studied do this and one records that concurrent sends on a single socket can misdeliver to the wrong chat. **We have not measured that in our own code**, so it is precaution rather than a reproduction of our own bug. Kept because the cost is one promise chain and the failure it guards against is a message reaching the wrong person.
868
+
869
+ _A timed-out send reports undetermined delivery, and is never retried._ A local timeout says the acknowledgement did not arrive, not that the message did not; retrying can duplicate — the failure this repository already shipped once, in the email backend re-answering its inbox.
870
+
871
+ _A connect that fails or is superseded tears its socket down._ A timed-out connect used to leave a live socket behind: it kept feeding inbound into the handler, and the retry opened a second live session — which on an unofficial automation is ban surface, not merely a leak. The same generation counter makes `disconnect()` during an in-flight `connect()` safe; without it the late success set `connected` over a backend with no socket, and every later send was refused until the object was rebuilt.
872
+
873
+ _The backend depends on a three-member socket contract we declare_, not on Baileys' types. That is what lets every test in this backend drive a fake and run with `baileys` absent — which matters, because a backend that could only be exercised with the real library installed is a backend exercised by nothing, and that is exactly how the `web` backend reached production unable to start.
874
+
875
+ _A retired connection attempt is ended, not merely silenced._ Retiring by generation made an abandoned attempt's listeners no-ops — including the one that resolves it — so nothing could settle it but the timeout. A `disconnect()` during pairing therefore blocked shutdown for the full 60s default while the socket it asked to close stayed live. And a socket that closed under the backend kept its reference until the next `connect()` overwrote it, so it was never ended and no later `disconnect()` could reach it. Both are fixed, as is a third window a later round found: a `disconnect()` landing while the factory itself was still awaiting — a dynamic import, the auth state off disk, and a network round-trip for the protocol version all happen before a socket exists — could not see an attempt that had no socket yet. Each has a test that fails when its fix alone is reverted.
876
+
877
+ _A failed connect says why._ `false` with no output cannot distinguish a network blip from a device the operator unlinked from their phone, and only one of those is worth retrying — a supervisor that cannot tell them apart retries forever against a session that can only be re-paired.
878
+
879
+ _Pairing has somewhere to go._ `printQRInTerminal` stays off — a library writing to stdout decides where a host's output goes — so the QR is handed to an `onQr` callback, defaulting to stderr. Without it a fresh session directory could only ever time out: there is no other way to pair.
880
+
881
+ **What no test here proves.** Nothing in this repository touches WhatsApp. Pairing needs a QR scan by a human and there is no WhatsApp in Docker, so protocol conformance, delivery, receipts and ban behaviour are unproven by this changeset and by every gate in this repository. A green suite means our logic does what we think — not that WhatsApp agrees.
882
+
883
+ The socket contract this backend depends on lost a member: `logout()` was declared and called by nothing, and on WhatsApp `logout()` **unpairs the device** — the opposite of what `disconnect()` means here. A dead member advertising a destructive capability is worse than an absent one.
884
+
885
+ `WhatsAppMessageEvent.whatsapp.backend` and `WhatsAppBackend.kind` gain a third member, so an exhaustive `switch` over either stops compiling until the case is handled. No call site in this repository switches on them.
886
+
887
+ ### Patch Changes
888
+
889
+ - e682180: **A message whose handler throws no longer kills the bot.** On Teams and on WhatsApp's web backend it did — not degraded delivery, an exit code. `Error: ... / Node.js v22.22.2`, and the next message never arrived.
890
+
891
+ Both dispatched with `void handler(event)`. `void` reads as "I am not waiting for this"; what it tells the runtime is "I am not handling the error", and under Node 22's default an unhandled rejection ends the process. Measured against both adapters through their own injection seams before the fix, and again after: the throw is now contained, named, and delivery continues.
892
+
893
+ **Discord and Telegram contained it but blamed the wrong thing.** The rejection escaped into the platform library's error channel, so a bug in the consumer's own handler surfaced as `[discord] client error` / `[telegram] bot error`. Anyone debugging that went looking in discord.js and grammy for a fault that was in their own code. Both now report `handler threw` and return `"handler_threw"` from the internal dispatch seam.
894
+
895
+ **WhatsApp Cloud dropped the rest of the batch, and made the platform resend it.** Meta packs several messages and their delivery receipts into one webhook, and the dispatch loop awaited each handler with nothing around it. One throw skipped every remaining message in the payload, skipped the status receipts, and rejected `handleWebhookPayload` — so the caller's route answered 500 and Meta redelivered the whole batch, replaying the messages that had already been handled. That is a duplicate-reply bug reached through a different door than the one fixed in #11. The same method also now answers `false` on a signed body that is not JSON, instead of throwing out of a method whose contract is `true`/`false`.
896
+
897
+ **Email gained a net it did not strictly need.** Its drain is written never to reject, and it does not — but both launch sites discard the promise, so that property was the only thing between a future edit and the same fatal rejection, and nothing enforced it. The catch now lives at the site that would pay for it.
898
+
899
+ **The contract is written down, and held to.** `BasePlatformAdapter.onInbound` now states it: a handler may throw, and an adapter must contain that throw, report it as the handler's failure rather than the platform's, and keep delivering. Eight of ten adapters had converged on exactly that with nothing recording it. `tests/lint/adapter-contract.test.ts` gains two invariants — every adapter names a handler throw as the handler's, and no adapter launches a user callback with a bare `void` — and both were checked against a deliberately reverted adapter to confirm they fire rather than pass vacuously.
900
+
901
+ - 9c35372: **Slack now answers `empty_text` for empty text, like the other nine adapters.** The contract states it without a condition — `sendMessage` with empty text returns `{ ok: false, code: "empty_text" }` — but Slack checked the connection first, so the same call answered `not_connected` there and `empty_text` everywhere else.
902
+
903
+ Nobody lost a delivery over it: both results are already `ok: false`. What broke is code that branches on the code — treating a caller's bad input one way and an unavailable transport another, with a retry or an alert behind the second. Written against the contract, that code did the right thing on nine platforms and the wrong thing on the tenth, with nothing to say why.
904
+
905
+ The connection guard keeps its reason (`this.app` is set before `app.start()` resolves, so a send in that window would otherwise leak through); only the order changed. Input first, transport second, which is what `rules/error-handling.md` § 2 asks for and what the other nine already did.
906
+
907
+ The cross-adapter gate gains the invariant, and it is checked against a deliberately reverted adapter. That check earned its keep immediately: the first version of the invariant read a window of raw source that its own explanatory comment filled, so it passed against the reverted adapter by matching the prose describing the rule. It now strips comments before asking — a gate answered by a comment is worse than no gate, because it reports coverage it does not have.
908
+
909
+ - b8ef098: **Every package now ships the licence it declares.** All twelve manifests in this repository declare `Apache-2.0`, and the repository had no `LICENSE` file at all — not at the root, and not in any package directory except `gateway-email`. So each published tarball asserted a licence while carrying none of its terms, and §4(a) of that licence requires a copy to travel with the distribution. Worse than a missing file: with no licence text anywhere, everything outside the manifests fell back to default copyright, which grants a recipient nothing.
910
+
911
+ The text is now at the repository root and inside every publishable package, byte-identical to the canonical Apache License 2.0 with the appendix filled in (`Copyright 2026 getloopscale.com`). The one pre-existing copy, in `gateway-email`, was replaced along with the rest: it carried the same truncated paragraph 4(d) found across the ecosystem, dropping "reasonable and customary use" from the NOTICE clause — a modified body under an unmodified SPDX identifier.
912
+
913
+ **The repository moved to the official `getloopscale` organization.** Existing clones and published URLs keep working through GitHub's permanent redirect; the root manifest now declares `Apache-2.0` explicitly rather than leaving the workspace root silent.
914
+
915
+ - 5bae032: Six defects that broke real conversations, found by testing the adapters against the live platforms instead of against fakes.
916
+
917
+ **LINE — no outbound message was ever delivered.** The adapter called the v9 SDK client with positional arguments while that client takes a single request object, so LINE received an empty request and rejected every send with a 400. Upgrade if you use this adapter at all: nothing it sent reached anyone.
918
+
919
+ **Telegram — the bot froze on long replies.** Any message over 4096 characters that began with an unclosed code span (a stray backtick) put the splitter into an infinite loop, hanging the process until it ran out of memory. Long agent answers now split correctly whatever markdown they contain.
920
+
921
+ **Mattermost — long messages silently vanished.** The adapter never split anything, so any reply over 16,383 characters was rejected by the server and the user simply saw nothing. Long replies are now split into parts Mattermost accepts.
922
+
923
+ **SMS — long messages were rejected from the hundredth part onward.** The `(i/N)` prefix outgrew the space reserved for it, pushing every later part past the provider's limit.
924
+
925
+ **Matrix and LINE — `connect()` reported success with an invalid token.** Both now verify the credential with the server before returning `true`, so a wrong token fails at startup instead of silently receiving nothing forever.
926
+
927
+ **Email and Teams — the bot could go permanently deaf.** Replacing an inbound handler and then disposing of the previous one removed the new handler as well, and the gateway stopped receiving messages with nothing logged.
928
+
929
+ Also: a `pre_inbound` hook that threw put its raw error text into the user's chat, which could expose internal details such as connection strings or tokens. Users now see only which hook failed; the detail goes to the server log, redacted.
930
+
931
+ WhatsApp additionally stops opening a second session when `connect()` is called twice, and its group mention filter no longer treats unrelated digits scattered through a message as a mention of the bot.
932
+
933
+ - 144b2ba: **The `post_outbound` hook now fires.** It is one of the three fire points `GatewayHook` documents and exports, and no production code had ever called it: `HookExecutor.firePostOutbound` existed, was typed, was unit-tested, and had exactly one caller in the repository — its own test.
934
+
935
+ That is the worst shape a broken contract can take. Registering a `post_outbound` hook for delivery auditing, outbound metrics or reply logging raised no error and produced no warning. The hook was simply never invoked, and the instrumentation a consumer believed they had did not exist.
936
+
937
+ Every reply now leaves through one path that sends and then reports, so the hook fires exactly once per attempt with `{ event, outbound, result }` — including the EC-D auto-reply sent when a `pre_inbound` hook blocks with a message, and including the attempt that finds no adapter registered for the event's platform. That last case matters more than it looks: a hook counting deliveries would otherwise omit precisely the replies that went nowhere.
938
+
939
+ The hook observes; it does not intercept. The adapter's `SendResult` reaches the caller of `reply` unchanged, and a hook that throws is contained by `HookExecutor`, so a broken observer cannot turn a delivered reply into a failed one.
940
+
941
+ - 111f837: **`stop()` no longer holds the process open for the whole drain window.** A bot that stopped on `SIGINT` sat there for ten more seconds before the process exited, with nothing running and nothing to wait for.
942
+
943
+ `stop()` drains in-flight handlers by racing them against a `drainTimeoutMs` timer. `Promise.race` settles on whichever branch finishes first and abandons the other — but an abandoned `setTimeout` is still a scheduled timer, and a scheduled timer keeps Node's event loop alive. The drain finished in under a millisecond; the timer it beat kept the process running for the remaining ten seconds. Measured before the fix: `stop()` returned after 0 ms, the process exited after 10 001 ms. After: 1 ms.
944
+
945
+ The delay only appeared once at least one event had been dispatched, since the drain branch is guarded on there being something in flight — which is to say, on every real bot rather than on any test that stopped a runner it had never used. Under an orchestrator that sends `SIGTERM` and then `SIGKILL`, the difference is whether shutdown is clean or forced.
946
+
947
+ The timer handle is now cleared in a `finally`, so the cleanup does not depend on which branch of the race won.
948
+
949
+ ## 0.5.1
950
+
951
+ ### Patch Changes
952
+
953
+ - b8ef098: **Every package now ships the licence it declares.** All twelve manifests in this repository declare `Apache-2.0`, and the repository had no `LICENSE` file at all — not at the root, and not in any package directory except `gateway-email`. So each published tarball asserted a licence while carrying none of its terms, and §4(a) of that licence requires a copy to travel with the distribution. Worse than a missing file: with no licence text anywhere, everything outside the manifests fell back to default copyright, which grants a recipient nothing.
954
+
955
+ The text is now at the repository root and inside every publishable package, byte-identical to the canonical Apache License 2.0 with the appendix filled in (`Copyright 2026 getloopscale.com`). The one pre-existing copy, in `gateway-email`, was replaced along with the rest: it carried the same truncated paragraph 4(d) found across the ecosystem, dropping "reasonable and customary use" from the NOTICE clause — a modified body under an unmodified SPDX identifier.
956
+
957
+ **The repository moved to the official `getloopscale` organization.** Existing clones and published URLs keep working through GitHub's permanent redirect; the root manifest now declares `Apache-2.0` explicitly rather than leaving the workspace root silent.
958
+
959
+ - 5bae032: Six defects that broke real conversations, found by testing the adapters against the live platforms instead of against fakes.
960
+
961
+ **LINE — no outbound message was ever delivered.** The adapter called the v9 SDK client with positional arguments while that client takes a single request object, so LINE received an empty request and rejected every send with a 400. Upgrade if you use this adapter at all: nothing it sent reached anyone.
962
+
963
+ **Telegram — the bot froze on long replies.** Any message over 4096 characters that began with an unclosed code span (a stray backtick) put the splitter into an infinite loop, hanging the process until it ran out of memory. Long agent answers now split correctly whatever markdown they contain.
964
+
965
+ **Mattermost — long messages silently vanished.** The adapter never split anything, so any reply over 16,383 characters was rejected by the server and the user simply saw nothing. Long replies are now split into parts Mattermost accepts.
966
+
967
+ **SMS — long messages were rejected from the hundredth part onward.** The `(i/N)` prefix outgrew the space reserved for it, pushing every later part past the provider's limit.
968
+
969
+ **Matrix and LINE — `connect()` reported success with an invalid token.** Both now verify the credential with the server before returning `true`, so a wrong token fails at startup instead of silently receiving nothing forever.
970
+
971
+ **Email and Teams — the bot could go permanently deaf.** Replacing an inbound handler and then disposing of the previous one removed the new handler as well, and the gateway stopped receiving messages with nothing logged.
972
+
973
+ Also: a `pre_inbound` hook that threw put its raw error text into the user's chat, which could expose internal details such as connection strings or tokens. Users now see only which hook failed; the detail goes to the server log, redacted.
974
+
975
+ WhatsApp additionally stops opening a second session when `connect()` is called twice, and its group mention filter no longer treats unrelated digits scattered through a message as a mention of the bot.
976
+
977
+ ## 0.5.0
978
+
979
+ ### Minor Changes
980
+
981
+ - Architecture-hardening (roadmap M0–M3): three new public primitives on the core barrel, plus a hook-engine relocation. No breaking changes.
982
+
983
+ - `chunkText(text, options)` — transport-agnostic, boundary-preferring text chunker. Single-sources the message-splitting logic the platform adapters share; reproduces the Slack-family (fixed window, space boundary, UTF-16 surrogate guard) and Telegram-family (soft window, newline-only) algorithms via options. Validates inputs (positive-integer `limit`, `safeLimit <= limit`) and throws `RangeError` on misuse (fail-fast — no infinite loop).
984
+ - `chunkByGrapheme(text, options)` — grapheme-cluster-safe (`Intl.Segmenter`) chunker shared by the LINE/SMS adapters; never severs an emoji, regional-indicator pair, or combining sequence.
985
+ - `GatewayConfigurationError` base + `GatewayConfigurationErrorOptions` — shared base for per-adapter `ConfigurationError` classes.
986
+ - `HookExecutor` moved from `hooks/types.ts` to `hooks/executor.ts` (public API byte-identical; re-exported unchanged from the barrel).
987
+
988
+ ## 0.4.1
989
+
990
+ ### Patch Changes
991
+
992
+ - e926cd9: Align the gateway cluster to the hardened `loopzero-sdk` 2.18.0 Harness (ecosystem M6). Bumped the `loopzero-sdk` peer + dev dependency from `^1.9.0` to `^2.18.0` across all 11 packages. The only consumed SDK surface is `Security.redact` (in the gateway core runner) — a stable public API (ADR D68) unchanged across 1.x→2.x — so the alignment is a pin bump, not a migration. Validated: all 11 packages typecheck + build + test green against 2.18.0 (543 tests passed). No dead/unwired surfaces (`no-stubs-no-mocks-no-wired` checklist clean).
993
+
994
+ ## [Unreleased]
995
+
996
+ ### Changed
997
+
998
+ - **Documentation only:** added `src/README.md` documenting the 6 single-file sub-folder cluster (`adapter/`, `delivery/`, `hooks/`, `runner/`, `session/`, `types/`) as intentional bounded future-extensibility scaffold (T10.2 of plan `arch-review-fixes-2026-06-06`; FO#4 of 2026-06-06 architecture audit). Rationale + ADR cross-references (D170-D177) + 12-month re-evaluation trigger documented. No code change.
999
+
1000
+ ## 2.0.0
1001
+
1002
+ ### Patch Changes
1003
+
1004
+ - Updated dependencies
1005
+ - loopzero-sdk@1.3.0
1006
+
1007
+ ## 1.0.0
1008
+
1009
+ ### Patch Changes
1010
+
1011
+ - Updated dependencies
1012
+ - loopzero-sdk@1.2.0
1013
+
1014
+ ## [Unreleased]
1015
+
1016
+ ### Added — Tier 1 Expansion variants (T0.1, ADRs D389/D397/D405/D413)
1017
+
1018
+ - `SMSMessageEvent` variant added to the `MessageEvent` discriminated union. Required for `loopzero-gateway-sms`.
1019
+ - `MattermostMessageEvent` variant added to the `MessageEvent` discriminated union. Required for `loopzero-gateway-mattermost`.
1020
+ - `LineMessageEvent` variant added to the `MessageEvent` discriminated union. Required for `loopzero-gateway-line`.
1021
+ - `MatrixMessageEvent` variant added to the `MessageEvent` discriminated union. Required for `loopzero-gateway-matrix`.
1022
+ - `PlatformName` union opened to include `"sms" | "mattermost" | "line" | "matrix"` (10 platforms total).
1023
+
1024
+ ### Changed
1025
+
1026
+ - Backward-compatible additive change — existing adapters / consumers continue to compile. The single `exhaustive switch` test was updated to cover the new 4 cases (EC-5 absorbed).
1027
+
1028
+ ## [0.4.0] - 2026-05-24
1029
+
1030
+ ### Added
1031
+
1032
+ - `EmailMessageEvent` variant added to the `MessageEvent` discriminated union (ADR D339). Required for `loopzero-gateway-email`.
1033
+ - `PlatformName` union opened to include `"email"`.
1034
+
1035
+ ### Changed
1036
+
1037
+ - Minor version bump (additive change — existing adapters / consumers unaffected).
1038
+
1039
+ ## [0.3.0] - 2026-05-23
1040
+
1041
+ ### Added
1042
+
1043
+ - `TeamsMessageEvent` variant added to the `MessageEvent` discriminated union (ADR D325). Required for `loopzero-gateway-teams`.
1044
+ - `PlatformName` union opened to include `"teams"`.
1045
+
1046
+ ### Changed
1047
+
1048
+ - Minor version bump (additive change — existing adapters / consumers unaffected).
1049
+
1050
+ ## [0.2.0] - 2026-05-23
1051
+
1052
+ ### Added
1053
+
1054
+ - `WhatsAppMessageEvent` variant added to the `MessageEvent` discriminated union (ADR D308). Required for `loopzero-gateway-whatsapp`.
1055
+ - `PlatformName` union opened to include `"whatsapp"`.
1056
+
1057
+ ### Changed
1058
+
1059
+ - Minor version bump (additive change — existing adapters / consumers unaffected).
1060
+
1061
+ ## [0.1.0] — 2026-05-20
1062
+
1063
+ ### Added
1064
+
1065
+ - Initial release. Core gateway primitives for `loopzero-sdk`.
1066
+ - `BasePlatformAdapter` abstract class — contract for transport adapters (ADR D172).
1067
+ - `MessageEvent` discriminated union with `platform` discriminator (ADR D173).
1068
+ - `GatewayRunner` — top-level orchestrator with drain timeout on `stop()` (EC-E).
1069
+ - `SessionRouter` — pure routing strategy; composes `Agent.resume` (ADR D174).
1070
+ - `DeliveryRouter` — outbound dispatch; composes `Cron` (ADR D175).
1071
+ - `HookExecutor` with `pre_inbound` / `post_outbound` / `on_error` (ADRs D176, D177).
1072
+ - `ctx.reply` auto-routes to the adapter matching `event.platform` (EC-G).
1073
+ - `{ block: true, message }` from `pre_inbound` triggers auto-reply before short-circuit (EC-D).
1074
+ - All runner error log paths wrap text in `Security.redact(...)` from `loopzero-sdk` (EC-F, ADR D68).