indigo-matter-bridge 0.17.0 → 0.17.2

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.
@@ -67,7 +67,7 @@
67
67
  * tested without a Matter stack. Callers hand in `{uniqueId, endpointNumber}`
68
68
  * pairs; deriving `uniqueId` from an Indigo device id is `endpoints.ts`'s job.
69
69
  */
70
- import { type DriftEntry, type OrphanRecord } from "./protocol.js";
70
+ import { type DriftEntry } from "./protocol.js";
71
71
  /** What the PRD §7 refuse-to-start decision is taken from. */
72
72
  export interface EndpointIdentityState {
73
73
  /** Does the Matter stack hold at least one fabric right now? */
@@ -166,17 +166,16 @@ export interface EndpointRecord {
166
166
  */
167
167
  numberVoid?: true;
168
168
  /**
169
- * Set by {@link EndpointMapStore.forget} (issue #219): the device was
170
- * un-exported,
171
- * so the entry must not be rebuilt by {@link EndpointMapStore.restorable}
172
- * — but unlike the pre-#219 behaviour, `role`/`label` are KEPT rather
173
- * than deleted, because they are the only evidence a future re-adopt UI
174
- * could match a recreated device against. Cleared the moment
175
- * {@link EndpointMapStore.check} sees the same `UniqueID` live again
176
- * (`noteRestorable`) — a live device is by
177
- * definition not orphaned, and re-exporting the same accessory must not
178
- * leave it permanently excluded from the next boot's pre-seeding. Absent
179
- * on every ordinary entry, same convention as `numberVoid`.
169
+ * Set by {@link EndpointMapStore.forget}: the device was un-exported, so
170
+ * the entry must not be rebuilt by {@link EndpointMapStore.restorable} —
171
+ * the actual fix for issue #141's appear-then-vanish churn.
172
+ * `role`/`label` are KEPT rather than deleted alongside it (they cost two
173
+ * strings, and nothing here has a reason to clear them). Cleared the
174
+ * moment {@link EndpointMapStore.check} sees the same `UniqueID` live
175
+ * again (`noteRestorable`) — a live device is by definition not
176
+ * orphaned, and re-exporting the same accessory must not leave it
177
+ * permanently excluded from the next boot's pre-seeding. Absent on every
178
+ * ordinary entry, same convention as `numberVoid`.
180
179
  */
181
180
  orphaned?: true;
182
181
  /**
@@ -191,27 +190,19 @@ export interface EndpointRecord {
191
190
  */
192
191
  battery?: true;
193
192
  /**
194
- * Set by {@link recordFor}/{@link noteRestorable} (issue #219 re-adopt):
195
- * the Indigo device CURRENTLY driving this published identity. Absent
196
- * means "the key's own derivation" — every pre-PR5 record, and every
197
- * un-re-adopted one, for which `parsePublishedId(uniqueId)?.deviceId` is
198
- * still the right answer (see {@link RestorableEndpoint.indigoDeviceId}).
193
+ * Set by {@link recordFor}/{@link noteRestorable}: the Indigo device
194
+ * CURRENTLY driving this published identity. Absent means "the key's own
195
+ * derivation" — every record whose identity has never been retargeted
196
+ * onto a different device, for which `parsePublishedId(uniqueId)?.deviceId`
197
+ * is still the right answer (see {@link RestorableEndpoint.indigoDeviceId}).
199
198
  *
200
199
  * **Replace-on-change, unlike {@link numberVoid}/{@link orphaned}/
201
- * {@link battery}'s add-only convention.** A re-adopt IS a change of
202
- * driving device — pinning the FIRST (now-deleted) device id forever
203
- * would make restore-on-start rebuild the accessory bound to a device
204
- * that no longer exists, which is the whole failure #219 exists to fix.
200
+ * {@link battery}'s add-only convention.** Migrating an accessory (issue
201
+ * #246) IS a change of driving device for an identity that stays LIVE the
202
+ * whole time — pinning the first device id forever would make
203
+ * restore-on-start rebuild the accessory bound to the wrong one.
205
204
  */
206
205
  deviceId?: number;
207
- /**
208
- * Set by {@link EndpointMapStore.forget} (issue #219) the moment an entry
209
- * is FIRST orphaned — an ISO-8601 stamp from the store's injected clock,
210
- * purely for the re-adopt picker's "un-exported on …" column. Absent on
211
- * every pre-PR5 orphan; the picker renders that as "date unknown" rather
212
- * than treating it as a fault (§4.2).
213
- */
214
- orphanedAt?: string;
215
206
  /**
216
207
  * Set by {@link EndpointMapStore.forget} when the caller has decided this
217
208
  * identity was RETIRED, not merely un-exported (issue #240): the published
@@ -219,19 +210,21 @@ export interface EndpointRecord {
219
210
  *
220
211
  * **The narrow rule, and it is narrow on purpose.** Only a LATER
221
212
  * GENERATION of the same identity — `indigo-7` → `indigo-7~2`, which is
222
- * what `protocol.ts`'s `supersedes()` tests — counts. A **re-adopt** is
223
- * the same shape at a glance (one removal plus one create, for one device)
224
- * and is deliberately NOT one: the identity a re-adopt leaves behind is an
225
- * ordinary orphan the picker must go on offering, PR5 design E5 in as many
226
- * words. Both node-side writers apply `supersedes()` before setting this,
227
- * whether the pair lands in one mutation (`node.ts`'s `forgetRemoved`) or
228
- * as two commands (`noteSupersessionIfPaired`).
229
- *
230
- * A superseded entry is {@link orphaned} too (it is not live), but it is
231
- * NOT a re-adopt candidate — {@link EndpointMapStore.restorable} and
232
- * {@link EndpointMapStore.orphans} both exclude it, because re-adopting it
233
- * would resurrect the OLD-role accessory under a number every paired
234
- * ecosystem has already processed a removal for.
213
+ * what `protocol.ts`'s `supersedes()` tests — counts. Migrating an
214
+ * accessory onto an already-exported device (issue #246, the ● case) is
215
+ * the same shape at a glance (one removal plus one create, for one
216
+ * device) and is deliberately NOT one: the target's own old identity and
217
+ * the newly-inherited one are unrelated strings, so it is left an
218
+ * ORDINARY orphan instead. Both node-side writers apply `supersedes()`
219
+ * before setting this, whether the pair lands in one mutation
220
+ * (`node.ts`'s `forgetRemoved`) or as two commands
221
+ * (`noteSupersessionIfPaired`).
222
+ *
223
+ * A superseded entry is {@link orphaned} too (it is not live), but it
224
+ * must never be REBUILT at the next restart —
225
+ * {@link EndpointMapStore.restorable} excludes it, because that would
226
+ * resurrect the OLD-role accessory under a number every paired ecosystem
227
+ * has already processed a removal for.
235
228
  */
236
229
  supersededBy?: string;
237
230
  }
@@ -285,13 +278,13 @@ export interface RestorableEndpoint {
285
278
  /** Issue #220 — `true` only when the persisted entry has ever seen one. */
286
279
  battery?: true;
287
280
  /**
288
- * Issue #219 — the device `node.ts`'s restore-on-start builds the spec
289
- * for. Resolved by {@link EndpointMapStore.restorable} from
290
- * {@link EndpointRecord.deviceId} where a re-adopt has set it, falling
281
+ * The device `node.ts`'s restore-on-start builds the spec for. Resolved
282
+ * by {@link EndpointMapStore.restorable} from
283
+ * {@link EndpointRecord.deviceId} where a migrate has set it, falling
291
284
  * back to the published identity's own derivation
292
- * (`parsePublishedId(uniqueId)?.deviceId`) for every pre-PR5 and
293
- * un-re-adopted entry — an entry that resolves to neither is not
294
- * restorable at all, so this is never `undefined` here.
285
+ * (`parsePublishedId(uniqueId)?.deviceId`) for every entry that has never
286
+ * been retargeted — an entry that resolves to neither is not restorable
287
+ * at all, so this is never `undefined` here.
295
288
  */
296
289
  indigoDeviceId: number;
297
290
  }
@@ -304,14 +297,14 @@ export interface EndpointMapLoad {
304
297
  problem?: string;
305
298
  /**
306
299
  * Entry-level oddities tolerated during the read, for the caller to put on
307
- * the §4.3 channel (issues #219/#240).
300
+ * the §4.3 channel (issue #240).
308
301
  *
309
302
  * `readRecord` is deliberately forgiving — a bad field costs the field, not
310
303
  * the file (see its own comment) — but "tolerated" is not the same as
311
- * "unremarkable", and a DISCARDED `supersededBy` re-arms a retired identity
312
- * as an ordinary re-adopt candidate. That is a decision about the user's
313
- * accessories, taken from a value we could not read, and it must not be
314
- * taken in silence.
304
+ * "unremarkable", and a DISCARDED `supersededBy` re-arms a retired
305
+ * identity as an ordinary, rebuildable one. That is a decision about the
306
+ * user's accessories, taken from a value we could not read, and it must
307
+ * not be taken in silence.
315
308
  */
316
309
  notes?: string[];
317
310
  }
@@ -400,11 +393,10 @@ export declare class EndpointMapStore {
400
393
  * whatever number came back. Excluding void entries here would only widen
401
394
  * the online-and-empty window issue #141 already closed, for no benefit.
402
395
  *
403
- * **`orphaned` IS part of this filter (issue #219).** A {@link forget}en
404
- * entry now keeps its `role`/`label` as re-adopt evidence rather than
405
- * losing them, so the orphan marker is what still keeps it out of the
406
- * pre-attach rebuild — exactly the churn {@link forget}'s own doc comment
407
- * exists to prevent, unaffected by role/label now surviving alongside it.
396
+ * **`orphaned` IS part of this filter (issue #141).** A {@link forget}en
397
+ * entry keeps its `role`/`label` (they cost nothing to keep), so the
398
+ * orphan marker is what actually keeps it out of the pre-attach rebuild —
399
+ * exactly the churn {@link forget}'s own doc comment exists to prevent.
408
400
  *
409
401
  * **So is `supersededBy` (issue #240), checked in its own right rather
410
402
  * than left to ride on `orphaned`.** The two are written together, but a
@@ -415,50 +407,19 @@ export declare class EndpointMapStore {
415
407
  * four conditions, not three: no `role`, no `label`, `orphaned`, or
416
408
  * `supersededBy`.
417
409
  *
418
- * **Resolves `indigoDeviceId` — and skips what it cannot (issue #219).**
419
- * `record.deviceId` wins where a re-adopt has set it; otherwise it falls
410
+ * **Resolves `indigoDeviceId` — and skips what it cannot.**
411
+ * `record.deviceId` wins where a migrate has set it; otherwise it falls
420
412
  * back to the published identity's own derivation
421
- * (`parsePublishedId(uniqueId)?.deviceId`), which is every pre-PR5 and
422
- * un-re-adopted entry. An entry with a `role`/`label` but neither source
423
- * of a device id — a map written by a NEWER node, or hand-edited — is
424
- * skipped and named on the §4.3 {@link warnings} channel (so it reaches
425
- * the user's Indigo log, not just stdout), in the same "cannot be rebuilt
426
- * by this bridge version" words `node.ts`'s own loop uses for an
413
+ * (`parsePublishedId(uniqueId)?.deviceId`), which is every entry that has
414
+ * never been retargeted. An entry with a `role`/`label` but neither
415
+ * source of a device id — a map written by a NEWER node, or hand-edited —
416
+ * is skipped and named on the §4.3 {@link warnings} channel (so it
417
+ * reaches the user's Indigo log, not just stdout), in the same "cannot be
418
+ * rebuilt by this bridge version" words `node.ts`'s own loop uses for an
427
419
  * unsupported `role`: this is the only place that ever sees such an entry,
428
420
  * since a skipped one never reaches that loop at all.
429
421
  */
430
422
  restorable(): RestorableEndpoint[];
431
- /**
432
- * §3.12's answer (issue #219) — every left-behind accessory identity the
433
- * re-adopt picker could plausibly offer, in map order (the order numbers
434
- * were first recorded).
435
- *
436
- * **Excludes `supersededBy` records (issue #240).** Those are orphaned
437
- * too, but re-adopting one would resurrect the OLD-role accessory under a
438
- * number every paired ecosystem has already processed a removal for —
439
- * see {@link EndpointRecord.supersededBy}.
440
- *
441
- * **Includes entries with no `role`/`label` (PR5 design E4, §4.2), unlike
442
- * {@link restorable}'s filter.** A pre-2026.16.2 bare `{number}` orphan —
443
- * from a plugin old enough to have deleted them on un-export — carries
444
- * nothing a replacement device could be matched against, so it can never
445
- * be re-adopted, but the ruling (PR5 design §5 E4) is to show it anyway: "the number
446
- * is reserved and the user is entitled to see why", as the picker's
447
- * "no role recorded, cannot be re-adopted" row (§4.2's third row). Callers
448
- * that need to tell the two shapes apart check `role`/`label` for
449
- * `undefined`, which {@link restorable}'s own skip-and-log already treats
450
- * as unrebuildable for the SAME entries.
451
- *
452
- * **Skips a key `parsePublishedId` refuses — PR5 design E11's `restorable()`
453
- * treatment, applied here for a sharper reason.** This list feeds the
454
- * re-adopt picker, and picking a row writes its key into the plugin's
455
- * `ExportStore` as a `publishedAs`, which the node then refuses at the
456
- * next attach with `malformed_args` — and an attach refusal takes EVERY
457
- * export offline, not just that one. So a hand-edited or newer-node key is
458
- * named once on the §4.3 channel and left out, rather than offered as a
459
- * route into a whole-bridge outage.
460
- */
461
- orphans(): OrphanRecord[];
462
423
  /**
463
424
  * True when the map is non-empty and EVERY entry in it is
464
425
  * {@link EndpointRecord.orphaned} — issue #222's distinction for
@@ -483,18 +444,15 @@ export declare class EndpointMapStore {
483
444
  * devices the user had already told us to stop exporting, and it regresses
484
445
  * XAC7's "un-exported accessories are gone".
485
446
  *
486
- * **The number AND the role/label stay (issue #219).** §3.3 already retained
487
- * the number on purpose, so re-adding the same device gets the same endpoint
447
+ * **The number AND the role/label stay.** §3.3 already retained the
448
+ * number on purpose, so re-adding the same device gets the same endpoint
488
449
  * number back and paired ecosystems see the accessory they already know
489
- * rather than a new one. Deleting `role`/`label` too — the pre-#219
490
- * behaviour — threw away the only evidence a future re-adopt UI could match
491
- * a *recreated* device (a factory-reset accessory that comes back with a new
492
- * `UniqueID`) against the endpoint it used to occupy. Instead the entry is
493
- * marked {@link EndpointRecord.orphaned}, which is what keeps it out of
494
- * {@link restorable}'s pre-attach rebuild — the actual thing #141 needed —
495
- * without destroying anything. `check`'s `noteRestorable` clears the marker
496
- * the moment the same `UniqueID` is live again, so a plain re-export is
497
- * unaffected.
450
+ * rather than a new one; `role`/`label` are simply never cleared alongside
451
+ * it. The entry is marked {@link EndpointRecord.orphaned}, which is what
452
+ * keeps it out of {@link restorable}'s pre-attach rebuild — the actual
453
+ * thing #141 needed — without destroying anything. `check`'s
454
+ * `noteRestorable` clears the marker the moment the same `UniqueID` is
455
+ * live again, so a plain re-export is unaffected.
498
456
  *
499
457
  * **Only a caller that watched a specific endpoint go may call this.** An
500
458
  * empty live set is not evidence of anything: a node that has never attached
@@ -506,22 +464,19 @@ export declare class EndpointMapStore {
506
464
  * nothing and the plugin's re-attach re-creates the same set.
507
465
  *
508
466
  * **`options.supersededBy` marks a role-change supersession (issue
509
- * #240) instead of an ordinary un-export**, and `orphanedAt` is stamped
510
- * from the store's injected `now()` the moment an entry is FIRST
511
- * orphaned — never re-stamped on a later call, so it always reads the
512
- * time the accessory actually left, not the time a supersession was
513
- * confirmed.
514
- *
515
- * **This is also how a TWO-COMMAND supersede gets its `supersededBy`
516
- * (§3 of the design: `replace()` sends `remove_endpoint` then
517
- * `upsert_endpoint` as separate commands).** The first call orphans the
518
- * entry with no `supersededBy` yet — the create has not happened. The
519
- * SECOND call, once the create lands, passes the SAME `uniqueId` again
520
- * with `{supersededBy}` — the guard below therefore does not stop at
467
+ * #240) instead of an ordinary un-export.**
468
+ *
469
+ * **This is also how a CROSS-COMMAND supersede gets its `supersededBy`**
470
+ * (a device un-exported by an `attach` reconcile, then later re-exported
471
+ * under a later generation of its identity as a SEPARATE
472
+ * `upsert_endpoint` — see `node.ts`'s `forgetRemoved`/
473
+ * `noteSupersessionIfPaired` pair). The first call orphans the entry
474
+ * with no `supersededBy` yet — the create has not happened. The SECOND
475
+ * call, once the create lands, passes the SAME `uniqueId` again with
476
+ * `{supersededBy}` — the guard below therefore does not stop at
521
477
  * "already orphaned" the way it does for a caller with nothing new to
522
478
  * say; a second call that has a `supersededBy` this record does not yet
523
- * carry still counts as a change, and only `orphanedAt` is protected
524
- * from being re-stamped.
479
+ * carry still counts as a change.
525
480
  *
526
481
  * Returns how many entries CHANGED — newly orphaned, newly given a
527
482
  * `supersededBy`, or both — so a no-op (no record at all, nothing worth
@@ -531,6 +486,37 @@ export declare class EndpointMapStore {
531
486
  forget(uniqueIds: readonly string[], options?: {
532
487
  supersededBy?: string;
533
488
  }): number;
489
+ /**
490
+ * A device is CONFIRMED GONE FOR GOOD — deleted from Indigo, or
491
+ * deliberately un-exported — so its record is dropped ENTIRELY rather
492
+ * than kept as an orphan (issue #274).
493
+ *
494
+ * **This is the one place a record's `number` is thrown away**, unlike
495
+ * every other mutation here ({@link forget}, {@link voidNumbers}), all of
496
+ * which keep it forever precisely so a retired number is never handed to
497
+ * a different accessory (ADR-0010). That guarantee still holds after this
498
+ * call: matter.js's OWN persisted allocation for the retired
499
+ * `Endpoint.id` — a separate store this file never touches — is what
500
+ * actually prevents reissue, and it is untouched by deleting our own
501
+ * witness of it. What is lost is {@link restorable}: it can only offer
502
+ * what is still in `#endpoints`, so a destroyed identity is gone — no
503
+ * pre-attach rebuild, ever again.
504
+ *
505
+ * **Only a caller certain the device will never come back may call
506
+ * this.** {@link EndpointMapStore.forget}'s doc comment explains why an
507
+ * ORDINARY un-export (an `attach` reconcile that simply does not mention
508
+ * an identity this pass) must stay soft: the node cannot tell a
509
+ * deliberate departure from a device that merely failed classification
510
+ * this one time (issue #274 constraint 2). `node.ts`'s `removeEndpoint`
511
+ * is the only caller, and it always does — every `remove_endpoint`
512
+ * command is the plugin confirming the driving device is gone for good.
513
+ *
514
+ * Returns how many entries actually existed and were removed, so a call
515
+ * over an already-forgotten or never-recorded `uniqueId` costs no disk
516
+ * write — the same idempotency `remove_endpoint` itself promises
517
+ * (§3.3: `{removed: false}` for an absent endpoint).
518
+ */
519
+ destroy(uniqueIds: readonly string[]): number;
534
520
  /**
535
521
  * Compare the live endpoint numbers against the map (PRD §4.3).
536
522
  *
@@ -551,42 +537,19 @@ export declare class EndpointMapStore {
551
537
  * what has to stop being true, not just the mismatch it was guarding
552
538
  * against.
553
539
  *
554
- * **A changed `deviceId` on an EXISTING record is logged as a re-adopt
555
- * (issue #219).** The record's device id is read before
556
- * {@link noteRestorable} overwrites it, so a real change (both sides
557
- * defined, and different) can still be told apart from a first sighting
558
- * (`added`, above — nothing to compare against) and from this build
559
- * simply filling in a field a pre-PR5 record never had (`record.deviceId`
560
- * was `undefined`, not merely different). Reported directly here, the same
561
- * place the `numberVoid` adoption above logs itself, because — like that
562
- * one — only `check` ever sees both the old and the new value at once; and
563
- * on the §4.3 {@link warnings} channel rather than stdout, because it is
564
- * the confirmation that the user's re-adopt actually landed.
540
+ * **A changed `deviceId` on an EXISTING record is logged.** The record's
541
+ * device id is read before {@link noteRestorable} overwrites it, so a
542
+ * real change (both sides defined, and different) can still be told
543
+ * apart from a first sighting (`added`, above — nothing to compare
544
+ * against) and from this build simply filling in a field the record never
545
+ * had (`record.deviceId` was `undefined`, not merely different). Reported
546
+ * directly here, the same place the `numberVoid` adoption above logs
547
+ * itself, because — like that one — only `check` ever sees both the old
548
+ * and the new value at once; and on the §4.3 {@link warnings} channel
549
+ * rather than stdout, because it is the confirmation that the change
550
+ * actually landed.
565
551
  */
566
552
  check(live: readonly LiveEndpointNumber[]): DriftEntry[];
567
- /**
568
- * Owner ruling 4 (issue #219) — a cheap nudge, not a decision. Called
569
- * from {@link check}'s `added` branch, before the brand-new record is
570
- * inserted: when the identity `check` is about to record for the FIRST
571
- * time has a `role` AND `label` that exactly match an existing
572
- * ORPHANED, non-superseded record, say so once — on the §4.3
573
- * {@link warnings} channel, because a nudge nobody reads is not a nudge —
574
- * naming the `Re-adopt a Matter accessory…` menu action. This is exactly the
575
- * motivating case for #219 — a device deleted, recreated and
576
- * re-exported under a brand-new identity, with the room now empty in
577
- * every ecosystem and no obvious reason why — offered before the user
578
- * has to notice and go looking for it.
579
- *
580
- * Deliberately does nothing else: it changes no state, blocks nothing,
581
- * and never fires for an update to an EXISTING identity (an ordinary
582
- * re-export, or a role-change supersede) — those are not the
583
- * "orphaned accessory nobody re-adopted yet" case this exists to
584
- * surface. An ambiguous match (more than one orphan with the same
585
- * role/label) logs against the first one found, in map order — good
586
- * enough for a nudge that only ever points a user at the menu, never
587
- * acts on their behalf.
588
- */
589
- private noteReadoptableMatch;
590
553
  /**
591
554
  * §3.10's preserving reset and the last-fabric self-reset (issue #140) —
592
555
  * mark every entry's number as no longer trustworthy, WITHOUT discarding