@witbitz/sdk 4.3.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +2 -2
  2. package/a2aCore.js +26 -5
  3. package/accountErase.js +6 -1
  4. package/accountRecord.js +2 -2
  5. package/agentDoorTools.js +28 -0
  6. package/chatLock.js +16 -0
  7. package/cloudDevicePins.js +2 -2
  8. package/codeAttachments.js +100 -0
  9. package/codeCache.js +149 -0
  10. package/codeCloud.js +0 -2
  11. package/codeComputers.js +1 -0
  12. package/codeFolders.js +116 -0
  13. package/codeHistory.js +76 -0
  14. package/codeLanguage.js +54 -0
  15. package/codeModes.js +2 -0
  16. package/codeProgress.js +54 -0
  17. package/codeSent.js +68 -0
  18. package/codeSubagents.js +107 -0
  19. package/codeTransport.js +22 -0
  20. package/connections.js +17 -18
  21. package/deviceAttest.js +9 -3
  22. package/idb.js +19 -3
  23. package/jobAgents.js +2 -2
  24. package/keptMerge.js +9 -2
  25. package/l1-worker-src.js +1 -1
  26. package/l1-worker.js +93 -30
  27. package/laneAssociation.js +68 -0
  28. package/laneConfig.js +4 -3
  29. package/manifest.json +80 -61
  30. package/memberChange.js +4 -2
  31. package/mirrorBatch.js +47 -0
  32. package/opRouting.js +10 -0
  33. package/package.json +21 -2
  34. package/pdfOptions.js +13 -0
  35. package/pdfText.js +107 -0
  36. package/pdfjs.mjs +28 -0
  37. package/pdfjs.worker.mjs +28 -0
  38. package/protectedLocal.js +18 -2
  39. package/removedMessage.js +1 -1
  40. package/roomEmbed.js +111 -0
  41. package/roomName.js +1 -1
  42. package/roomRoster.js +21 -5
  43. package/rosterCount.js +6 -3
  44. package/sdkA2A.js +160 -40
  45. package/sdkAccount.js +17 -4
  46. package/sdkAccountDoc.js +11 -3
  47. package/sdkAccountSections.js +117 -8
  48. package/sdkBackup.js +35 -8
  49. package/sdkCloudDevice.js +8 -2
  50. package/sdkComputers.js +582 -53
  51. package/sdkDictation.js +114 -24
  52. package/sdkErase.js +9 -4
  53. package/sdkExports.js +4 -2
  54. package/sdkLaneLink.js +3 -3
  55. package/sdkPlan.js +4 -2
  56. package/sdkRekey.js +50 -17
  57. package/sdkReport.js +1 -1
  58. package/sdkSafeMedia.js +1 -1
  59. package/sdkSpeech.js +19 -2
  60. package/sdkTemporaryRooms.js +123 -0
  61. package/sdkVault.js +66 -10
  62. package/sentinelRelease.js +1 -0
  63. package/sharedViews.js +17 -3
  64. package/siri.js +114 -7
  65. package/spaceClient.js +16 -5
  66. package/spaceEmailGate.js +2 -2
  67. package/spaceTemplates.js +99 -0
  68. package/speechOut.js +4 -2
  69. package/store.js +83 -14
  70. package/sw-notif-core.js +9 -7
  71. package/turnVerdict.js +1 -0
  72. package/vault-core.js +480 -112
  73. package/vault-kit.mjs +2 -2
  74. package/vault-screens.js +5 -7
  75. package/vaultAtRest.js +35 -4
  76. package/vaultKeep.js +9 -3
  77. package/vaultWorkerHost.js +23 -4
  78. package/witbitz-admin.mjs +12 -11
  79. package/witbitz-sdk.d.ts +115 -24
  80. package/witbitz-sdk.js +572 -149
package/l1-worker.js CHANGED
@@ -12,6 +12,7 @@
12
12
  // room, `auth(room)` round-trips to the main thread via {authReq}. The enclave tier (mkPub/enclave) is
13
13
  // read SYNCHRONOUSLY by keyFields, so we keep a pushed snapshot {enclaveKey, enclaveRooms} and read it
14
14
  // locally rather than round-trip.
15
+ import { routingIndex } from './opRouting.js'
15
16
  import { prefetchUsable, positionOf, prefetchAnswer, prefetchHashKey } from './prefetchPoll.js'
16
17
  import { makeSpaceClient, setAttestProvider, setPushSelf, setPushAcct, pushAcctSecretOf, viewingTag } from './spaceClient.js'
17
18
  import { idb } from './idb.js'
@@ -57,12 +58,24 @@ const TEMP_SK = /^[A-Za-z0-9_-]{43}$/
57
58
  // ROOM STREAMS: room → { s, holders }. The stream client needs mk, so it runs in this realm; only EVENTS go out — the
58
59
  // reply text as it grows (the same plaintext a poll's partialText already carries out), "poll now", "the turn ended".
59
60
  // Several frames can share this worker (the hoisted vault: the app + a lane panel), hence a holder count.
61
+ const grantsByRoom = new Map()
60
62
  const streams = new Map()
63
+ function rekeyStream(room, mk) {
64
+ const held = streams.get(room)
65
+ if (!held?.s || held.mk === mk) return
66
+ held.s.stop()
67
+ grantsByRoom.delete(room)
68
+ held.mk = mk
69
+ held.grants = null
70
+ held.s = openStreamHere(room, mk, null, held.tag)
71
+ }
61
72
  const streamFeed = (room, result) => {
62
73
  const h = streams.get(room)
63
- if (!h || !result || result.status !== 200) return
64
- if (Array.isArray(result.streamGrants)) { h.s.setGrants(result.streamGrants); h.grants = result.streamGrants }
65
- h.s.sync(typeof result.partialText === 'string' ? result.partialText : '')
74
+ if (!result || result.status !== 200) return
75
+ if (Array.isArray(result.streamGrants)) grantsByRoom.set(room, result.streamGrants)
76
+ if (!h) return
77
+ if (Array.isArray(result.streamGrants)) { h.s?.setGrants(result.streamGrants); h.grants = result.streamGrants }
78
+ h.s?.sync(typeof result.partialText === 'string' ? result.partialText : '')
66
79
  }
67
80
  const mks = new Map() // room → mk — the worker's authoritative key store (A2b); mk never posts back out
68
81
  // §9 SPLIT-KEY (confinement mode): a split room's key store is the user's userShare + the commit. resolveMk fetches the
@@ -111,7 +124,7 @@ const backwards = (room, held, incoming, ep) => held !== incoming && (Number(ep)
111
124
  // never hands the frame or the next worker the old one. Only a key with an epoch, only when it changed. The vault page is
112
125
  // this worker's owner and already holds every key; the regular app's page ignores the message.
113
126
  const tellEpoch = (room, ep, key) => { if (volatile.has(room) || String(room).startsWith('tmp-')) return; try { self.postMessage({ t: 'keyEpoch', room, ep, ...key }) } catch { /* */ } } // never a memory-only (attested) or temporary room's key: the vault would keep it in its account cache
114
- const keep = (room, mk, ep) => { if (backwards(room, mks.get(room), mk, ep)) return false; if ((Number(ep) || 0) > 0 && (mks.get(room) !== mk || Number(ep) > (eps.get(room) || 0))) tellEpoch(room, Number(ep), { mk }); if (ep) noteEp(room, ep); mks.set(room, mk); persist('mk:' + room, mk); deriveNotifKey(mk).then((nk) => persistNk(room, nk)).catch(() => {}) } // + NK mirror: every mk the kernel holds (normal OR reconstructed-split) yields a push-preview key, so a background notification for THIS room shows sender+text (vault-sw.js notifPreview), not the generic nudge
127
+ const keep = (room, mk, ep) => { if (backwards(room, mks.get(room), mk, ep)) return false; if ((Number(ep) || 0) > 0 && (mks.get(room) !== mk || Number(ep) > (eps.get(room) || 0))) tellEpoch(room, Number(ep), { mk }); if (ep) noteEp(room, ep); mks.set(room, mk); rekeyStream(room, mk); persist('mk:' + room, mk); deriveNotifKey(mk).then((nk) => persistNk(room, nk)).catch(() => {}) } // + NK mirror: every mk the kernel holds (normal OR reconstructed-split) yields a push-preview key, so a background notification for THIS room shows sender+text (vault-sw.js notifPreview), not the generic nudge
115
128
  // WHY a room has no key, per room — the worker's own verdict rides the no_key answer (the owner's trail said only "no key on
116
129
  // this device" while the index held a share for every room, 2026-10-03).
117
130
  const APPSHARE_URL = (() => { try { const o = self.location && self.location.origin; return (o && o !== 'null') ? o + '/api/appshare' : '/api/appshare' } catch (e) { return '/api/appshare' } })()
@@ -138,17 +151,18 @@ async function heldMatchesShare (room, have) {
138
151
  if (ok) { heldOk.set(room, have); return true }
139
152
  dropOldKey(room); return false
140
153
  }
141
- const dropOldKey = (room) => { if (!mks.has(room)) return; mks.delete(room); keysReady.then(() => idb.del('mk:' + room)).catch(() => {}) }
154
+ const dropOldKey = (room) => { if (!mks.has(room)) return; const h = streams.get(room); if (h) { h.s?.stop(); h.mk = null; h.grants = null }; grantsByRoom.delete(room); mks.delete(room); keysReady.then(() => idb.del('mk:' + room)).catch(() => {}) }
142
155
  const keepSplit = (room, sp, ep) => { if (backwards(room, splits.get(room) && splits.get(room).userShare, sp.userShare, ep)) return false; if ((Number(ep) || 0) > 0 && ((splits.get(room) || {}).userShare !== sp.userShare || Number(ep) > (eps.get(room) || 0))) { tellEpoch(room, Number(ep), { split: { userShare: sp.userShare, commit: sp.commit || '' } }); if (Number(ep) > (eps.get(room) || 0) || (splits.get(room) || {}).userShare !== sp.userShare) dropOldKey(room) } if (ep) noteEp(room, ep); const held = splits.get(room); if (held && held.userShare !== sp.userShare) { const alts = splitAlts.get(room) || []; if (!alts.some((a) => a.userShare === held.userShare)) splitAlts.set(room, [held, ...alts].slice(0, 4)) } splits.set(room, sp); persist('us:' + room, sp) }
143
156
  // The mirror of keep/keepSplit, and the thing that makes "delete this Space" mean anything: without it the app cleared
144
157
  // localStorage while the WORKER kept the key — in memory AND in idb, from which a freshly-created worker reloads it at
145
158
  // boot (the idb.entries('mk:') restore below). So a deleted room's key came BACK on the next page load. Clears every
146
159
  // trace: the live maps, the persisted mk, the derived notification key, and the split half.
147
160
  const forget = (room) => {
161
+ grantsByRoom.delete(room); streams.get(room)?.s?.stop(); streams.delete(room)
148
162
  mks.delete(room); splits.delete(room); eps.delete(room)
149
163
  for (const prefix of ['mk:', 'us:', 'nk:']) parked.delete(prefix + room)
150
164
  lastPos.delete(room); heldOk.delete(room); splitAlts.delete(room)
151
- return Promise.all([idb.del('mk:' + room), idb.del('nk:' + room), idb.del('us:' + room), idb.del('ep:' + room), idb.del('cnt:' + room)]).catch(() => {})
165
+ return Promise.all(['mk:', 'nk:', 'us:', 'ep:', 'cnt:'].map(prefix => idb.delStrict(prefix + room)))
152
166
  }
153
167
  async function resolveMk(room) {
154
168
  // ⚑ WAIT for the idb key map. EVERY page load starts a FRESH worker (plus browsers evict them), and the map loads
@@ -252,7 +266,7 @@ setAttestProvider(attestShim)
252
266
  // push handler leaves a PREFETCHED poll answer here and reads the room's position from here. Every call is bounded —
253
267
  // a hung database must never hold a poll.
254
268
  const IDB_WAIT = 2500
255
- const idbOpen = () => new Promise((res) => { const t = setTimeout(() => res(null), IDB_WAIT); try { const r = indexedDB.open('spaces', 1); r.onupgradeneeded = () => { try { r.result.createObjectStore('kv') } catch { /* */ } }; r.onsuccess = () => { clearTimeout(t); res(r.result) }; r.onerror = () => { clearTimeout(t); res(null) } } catch { clearTimeout(t); res(null) } })
269
+ const idbOpen = () => new Promise((res) => { const t = setTimeout(() => res(null), IDB_WAIT); try { const r = indexedDB.open('spaces', 1); r.onupgradeneeded = () => { try { r.result.createObjectStore('kv') } catch { /* */ } }; r.onsuccess = () => { clearTimeout(t); const db = r.result; db.onversionchange = () => db.close(); res(db) }; r.onerror = () => { clearTimeout(t); res(null) } } catch { clearTimeout(t); res(null) } })
256
270
  const idbGet = async (k) => { try { const db = await idbOpen(); if (!db) return null; return await new Promise((res) => { const t = setTimeout(() => res(null), IDB_WAIT); const q = db.transaction('kv', 'readonly').objectStore('kv').get(k); q.onsuccess = () => { clearTimeout(t); res(q.result || null) }; q.onerror = () => { clearTimeout(t); res(null) } }) } catch { return null } }
257
271
  const idbSet = async (k, v) => { try { const db = await idbOpen(); if (!db) return false; return await new Promise((res) => { const t = setTimeout(() => res(false), IDB_WAIT); const q = db.transaction('kv', 'readwrite').objectStore('kv').put(v, k); q.onsuccess = () => { clearTimeout(t); res(true) }; q.onerror = () => { clearTimeout(t); res(false) } }) } catch { return false } }
258
272
  const idbDel = async (k) => { try { const db = await idbOpen(); if (!db) return false; return await new Promise((res) => { const t = setTimeout(() => res(false), IDB_WAIT); const q = db.transaction('kv', 'readwrite').objectStore('kv').delete(k); q.onsuccess = () => { clearTimeout(t); res(true) }; q.onerror = () => { clearTimeout(t); res(false) } }) } catch { return false } }
@@ -377,10 +391,13 @@ self.onmessage = async (e) => {
377
391
  case 'wipeKeys': { // root-vault only: parked/opaque keys count even when no room list can name them
378
392
  storageWiped = true; storageEpoch++
379
393
  await keysReady
394
+ for (const h of streams.values()) h.s?.stop()
395
+ streams.clear(); grantsByRoom.clear()
380
396
  mks.clear(); splits.clear(); parked.clear(); splitAlts.clear(); eps.clear(); heldOk.clear(); lastPos.clear()
381
- for (const k of await idb.keysRaw('')) await idb.delRaw(k)
382
- publishPresence()
383
- self.postMessage({ id: m.id, result: true })
397
+ ids.clear()
398
+ try { await idb.clearStrict(); self.postMessage({ id: m.id, result: true }) }
399
+ catch (error) { self.postMessage({ id: m.id, error: String(error?.message || error) }) }
400
+ finally { publishPresence() }
384
401
  return
385
402
  }
386
403
  case 'volatile': { // {rooms} → these rooms' keys are memory-only from now on: drop what is stored, write nothing
@@ -417,9 +434,13 @@ self.onmessage = async (e) => {
417
434
  case 'forget': { // {room} → DROP the key. AWAITS the idb deletes before replying: the caller holds
418
435
  // navigation until it resolves, and a dedicated worker dies with its page — a fire-and-forget delete could be
419
436
  // cut off mid-write, leaving the key in idb for the next worker to reload.
437
+ try {
420
438
  await keysReady
421
- if (m.room) { await forget(m.room); publishPresence() }
422
- if (m.id != null) self.postMessage({ id: m.id, result: true })
439
+ if (m.room) await forget(m.room)
440
+ if (m.id != null) self.postMessage({ id: m.id, result: true })
441
+ } catch (error) {
442
+ if (m.id != null) self.postMessage({ id: m.id, error: String(error?.message || error) })
443
+ } finally { publishPresence() }
423
444
  return
424
445
  }
425
446
  case 'setPushAcct': { // {room} = the account's INDEX room → derive the account push secret from ITS key, here,
@@ -447,7 +468,7 @@ self.onmessage = async (e) => {
447
468
  // A stream opened before the endpoint arrived carries no viewing tag: reopen it with one (the server then skips this
448
469
  // device's tickle for the room on screen). Same room, same key; only the socket's name changes.
449
470
  for (const [room, h] of streams) {
450
- try { const tag = await viewingTag(room); if (tag && tag !== h.tag && h.mk) { h.s.stop(); h.s = openStreamHere(room, h.mk, h.grants || null, tag); h.tag = tag } } catch { /* the old socket stays */ }
471
+ try { const tag = await viewingTag(room); if (tag && tag !== h.tag && h.mk) { h.s?.stop(); h.s = openStreamHere(room, h.mk, h.grants || null, tag); h.tag = tag } } catch { /* the old socket stays */ }
451
472
  }
452
473
  if (m.id != null) self.postMessage({ id: m.id, result: true })
453
474
  return
@@ -599,6 +620,15 @@ self.onmessage = async (e) => {
599
620
  // not leaving one arrival path out.
600
621
  // ⛔ …but NEVER to a keyless caller (above): in the hosted app this answer crossed into the app frame and carried every
601
622
  // room key and split share of the account on every index sync. It gets `splits` alone.
623
+ if (name === 'index' && st && typeof st === 'object') {
624
+ for (const field of ['pipesRoom', 'msgsRoom']) {
625
+ const ptr = st[field]
626
+ if (!ptr?.room) continue
627
+ if (ptr.mk) keep(ptr.room, ptr.mk)
628
+ if (keylessAsk) st = { ...st, [field]: { room: ptr.room } }
629
+ }
630
+ publishPresence()
631
+ }
602
632
  self.postMessage({ id, result: { status: 200, state: st, splits: splitRooms, ...(keylessAsk ? {} : { mkeys: mirror }), ...(Number.isInteger(r.v) ? { v: r.v } : {}) } }) // v: the version a write names (accountStores put ifV)
603
633
  } catch (err) { self.postMessage({ id, error: 'indexRead: ' + String((err && err.message) || err) }) }
604
634
  return
@@ -610,6 +640,7 @@ self.onmessage = async (e) => {
610
640
  await keysReady // NEVER write the index from a half-loaded key map — an empty `mks` would strip every room's key (below)
611
641
  if (indexMk && !mks.get(indexRoom)) { keep(indexRoom, indexMk); publishPresence() } // index ROOM key passed by the app (adopted-from-backup case)
612
642
  let p = { ...(patch || {}) }
643
+ let previousIndex
613
644
  if (p.rooms && typeof p.rooms === 'object') {
614
645
  // PRESERVE keys we don't hold. The patch arrives KEYLESS (indexRead strips keys before handing it up), so a room
615
646
  // whose key is missing from THIS worker used to be dropped outright — silently deleting that key from the shared
@@ -619,6 +650,7 @@ self.onmessage = async (e) => {
619
650
  try {
620
651
  let s = null; const rr = await acct.get(indexRoom, mks.get(indexRoom) || indexMk, name, { plainOpen: unzipDoc })
621
652
  if (rr && rr.status === 200 && rr.state) s = rr.state
653
+ previousIndex = s
622
654
  if (s && s.rooms && typeof s.rooms === 'object') cur = s.rooms
623
655
  } catch { /* read failed → fall back to inject-what-we-hold (the pre-existing behaviour) */ }
624
656
  const rooms = {}
@@ -637,6 +669,14 @@ self.onmessage = async (e) => {
637
669
  publishPresence()
638
670
  }
639
671
  // ⛔ SEALED on the device — the doc carries every room key (accountStores.js); without the account key nothing is written
672
+ if (name === 'index') for (const field of ['pipesRoom', 'msgsRoom']) {
673
+ const ptr = p[field]
674
+ if (!ptr?.room || ptr.mk) continue
675
+ const saved = previousIndex?.[field]
676
+ const mk = (saved?.room === ptr.room && saved.mk) || mks.get(ptr.room)
677
+ if (!mk) throw new Error('The account room key is unavailable. Retry sync.')
678
+ p[field] = { room: ptr.room, mk }
679
+ }
640
680
  const r = await acct.put(indexRoom, mks.get(indexRoom) || indexMk, name, p, summary, by, { ifV }) // ifV: only over the version the app merged
641
681
  self.postMessage({ id, result: { status: (r && r.status) || 0, bytes: _jsonBytes(p), z: true, ...(r && r.error ? { error: r.error } : {}) } })
642
682
  } catch (err) { self.postMessage({ id, error: 'indexWrite: ' + String((err && err.message) || err) }) }
@@ -731,23 +771,32 @@ self.onmessage = async (e) => {
731
771
  })()
732
772
  return
733
773
  }
734
- case 'streamOpen': { // {room, grants} → hold this room's stream (one socket however many frames ask)
735
- const { room, grants } = m
736
- const h = streams.get(room)
737
- if (h) { h.holders++; if (Array.isArray(grants)) { h.s.setGrants(grants); h.grants = grants } return }
738
- let mk = null
739
- try { await keysReady } catch { /* */ }
740
- try { mk = (typeof m.mk === 'string' && m.mk) || mks.get(room) || await resolveMk(room) } catch { mk = null } // m.mk: an account room's pointer key (index / pipes), as indexRead takes it
741
- if (!mk || streams.has(room)) { if (streams.has(room)) streams.get(room).holders++; return } // no key here → no stream (the page keeps polling)
742
- const tag = await viewingTag(room).catch(() => '') // THIS device is viewing the room (no tickle for it while the socket is open)
743
- if (streams.has(room)) { streams.get(room).holders++; return } // another open won the race during the await
744
- const s = openStreamHere(room, mk, grants, tag)
745
- streams.set(room, { s, holders: 1, mk, tag, grants: Array.isArray(grants) ? grants : null })
774
+ case 'streamOpen': {
775
+ const { room } = m
776
+ const grants = m.grants || grantsByRoom.get(room)
777
+ let held = streams.get(room)
778
+ if (held) {
779
+ held.holders++
780
+ if (Array.isArray(grants)) { held.grants = grants; held.s?.setGrants(grants) }
781
+ return
782
+ }
783
+ held = { holders: 1, mk: null, s: null, tag: '', grants: Array.isArray(grants) ? grants : null }
784
+ streams.set(room, held)
785
+ try {
786
+ await keysReady
787
+ const mk = (typeof m.mk === 'string' && m.mk) || mks.get(room) || await resolveMk(room)
788
+ if (streams.get(room) !== held) return
789
+ if (!mk) { streams.delete(room); return }
790
+ const tag = await viewingTag(room).catch(() => '')
791
+ if (streams.get(room) !== held) return
792
+ held.tag = tag; held.mk = mks.get(room) || mk
793
+ held.s = openStreamHere(room, held.mk, held.grants, tag)
794
+ } catch (error) { if (streams.get(room) === held) streams.delete(room) }
746
795
  return
747
796
  }
748
- case 'streamClose': { // {room} → one holder fewer; the last one closes the socket
749
- const h = streams.get(m.room)
750
- if (h && --h.holders <= 0) { h.s.stop(); streams.delete(m.room) }
797
+ case 'streamClose': {
798
+ const held = streams.get(m.room)
799
+ if (held && --held.holders <= 0) { held.s?.stop(); streams.delete(m.room) }
751
800
  return
752
801
  }
753
802
  case 'op': { // {id, op, room, args} → client[op](room, mks[room], …args) → {id, result}
@@ -762,8 +811,22 @@ self.onmessage = async (e) => {
762
811
  // hold no identity for stays unsigned (open/legacy), unchanged. Only substitutes when the arg is absent — an app
763
812
  // that still passes identity (flag off / email turn) is untouched.
764
813
  if (op === 'turn' && (aa[1] == null) && ids.has(room)) aa[1] = ids.get(room)
765
- for (const a of aa) { if (a && typeof a === 'object' && a.bridgeRoom && !a.bridgeMk) { const bmk = mks.get(a.bridgeRoom) || await resolveMk(a.bridgeRoom); if (bmk) a.bridgeMk = bmk } }
766
- for (const a of aa) { if (a && typeof a === 'object' && Array.isArray(a.links)) for (const l of a.links) { if (l && typeof l === 'object' && l.room && !l.mk) { const lmk = mks.get(l.room) || await resolveMk(l.room).catch(() => null); if (lmk) l.mk = lmk } } } // a lane's linked rooms named by id (a vault's page holds no keys) // worker-resolve a lane bridge's key (?atlaspipes: laneBridge passes bridgeRoom only). resolveMk (not just the cache) so a split shared room whose mk isn't cached yet still gets its bridge injected. Inert when bridgeMk is already present.
814
+ const index = routingIndex(op)
815
+ if (index >= 0 && aa[index] && typeof aa[index] === 'object') {
816
+ const route = { ...aa[index] }
817
+ aa[index] = route
818
+ if (route.bridgeRoom && !route.bridgeMk) {
819
+ const key = mks.get(route.bridgeRoom) || await resolveMk(route.bridgeRoom)
820
+ if (key) route.bridgeMk = key
821
+ }
822
+ if (op === 'turn' && Array.isArray(route.links)) {
823
+ route.links = await Promise.all(route.links.map(async link => {
824
+ if (!link?.room || link.mk) return link
825
+ const key = mks.get(link.room) || await resolveMk(link.room).catch(() => null)
826
+ return key ? { ...link, mk: key } : link
827
+ }))
828
+ }
829
+ }
767
830
  const mkHere = await resolveMk(room) // §9: reconstruct a split room's mk (fetch appShare + combine) on demand
768
831
  let result = null
769
832
  let pfNote = '' // what the prefetch lookup found, for the page's tap timeline ('' = not looked up)
@@ -0,0 +1,68 @@
1
+ // Room activity and changes to who a private room is linked to have distinct clocks.
2
+ export function associationTime(record, now = Date.now()) {
3
+ return Math.max(now, (Number(record?.associationAt || record?.at) || 0) + 1)
4
+ }
5
+ // Normalize legacy records before cursor or key maintenance can move their activity time.
6
+ export function reconcilePrivateRooms(pipes) {
7
+ const byRoom = new Map()
8
+ for (const pipe of Object.values(pipes)) {
9
+ if (pipe?.kind === 'lane-lane') { pipe.associationAt ||= Number(pipe.at) || 1; continue }
10
+ if (pipe?.kind !== 'private-lane') continue
11
+ pipe.associationAt ||= Number(pipe.at) || 1
12
+ const room = pipe.lane?.room
13
+ if (!room || pipe.removed) continue
14
+ if (!byRoom.has(room)) byRoom.set(room, [])
15
+ byRoom.get(room).push(pipe)
16
+ }
17
+ const conflicting = new Set()
18
+ for (const parents of byRoom.values()) {
19
+ for (const pipe of parents) {
20
+ const upstream = byRoom.get(pipe.shared?.room)
21
+ if (!upstream) continue
22
+ conflicting.add(pipe)
23
+ for (const other of upstream) conflicting.add(other)
24
+ }
25
+ }
26
+ for (const parents of byRoom.values()) {
27
+ if (parents.length < 2 && !conflicting.has(parents[0])) continue
28
+ const decision = Math.max(...parents.map(p => p.associationAt))
29
+ for (const pipe of parents) {
30
+ pipe.removed = true
31
+ pipe.associationAt = decision
32
+ pipe.cursor = 0
33
+ }
34
+ }
35
+ return pipes
36
+ }
37
+
38
+ export function preferredAssociation(left, right) {
39
+ if (!left || !right) return left || right
40
+ const explicit = record => Number(record.associationAt) || (record.kind === 'private-lane' || record.kind === 'lane-lane' || record.detachedLane || record.removed ? Number(record.at) || 0 : 0)
41
+ const a = explicit(left), b = explicit(right)
42
+ if (a !== b) return a > b ? left : right
43
+ if (left.detachedLane || left.removed) return left
44
+ if (right.detachedLane || right.removed) return right
45
+ const activity = Number(right.at || 0) - Number(left.at || 0)
46
+ if (activity) return activity > 0 ? right : left
47
+ const destination = record => record.lane?.room || (typeof record.shared === 'string' ? record.shared : '') || ''
48
+ return destination(right) > destination(left) ? right : left
49
+ }
50
+
51
+ /** A private room cannot itself parent another private room. Suspend both edges of any merged chain. */
52
+ export function reconcileAccountLanes(rooms) {
53
+ const parents = new Map(rooms.filter(r => r.shared && !r.detachedLane).map(r => [r.room, r]))
54
+ const suspend = new Map()
55
+ for (const child of parents.values()) {
56
+ const parent = parents.get(child.shared)
57
+ if (!parent) continue
58
+ const at = Math.max(Number(child.associationAt || child.at) || 1, Number(parent.associationAt || parent.at) || 1)
59
+ for (const r of [parent, child]) suspend.set(r.room, Math.max(at, suspend.get(r.room) || 0))
60
+ }
61
+ return rooms.map(r => {
62
+ if (!suspend.has(r.room)) return r
63
+ const detached = { ...r, kind: 'space', detachedLane: true, associationAt: suspend.get(r.room) }
64
+ delete detached.shared
65
+ delete detached.laneOrigin
66
+ return detached
67
+ })
68
+ }
package/laneConfig.js CHANGED
@@ -15,11 +15,12 @@ const toolName = (t) => (t && typeof t === 'object' ? t.name : t)
15
15
  /** The shared room's tools a lane takes on (the app's lanes do: the member's assistant can search what the room's can). */
16
16
  export function inheritToolsFrom (sharedConfig) {
17
17
  const c = sharedConfig && typeof sharedConfig === 'object' ? sharedConfig : null
18
- if (!c || !Array.isArray(c.tools)) return {}
18
+ const inherited = c && (c.platformTools === false || Array.isArray(c.platformTools)) ? { platformTools: Array.isArray(c.platformTools) ? [...c.platformTools] : false } : {}
19
+ if (!c || !Array.isArray(c.tools)) return inherited
19
20
  const tools = c.tools.filter((t) => !LANE_WITHHELD.has(toolName(t)))
20
- if (!tools.length) return {}
21
+ if (!tools.length) return inherited
21
22
  const immediate = Array.isArray(c.immediateTools) ? c.immediateTools.filter((n) => !LANE_WITHHELD.has(n)) : []
22
- return { tools, ...(immediate.length ? { immediateTools: immediate } : {}) }
23
+ return { ...inherited, tools, ...(immediate.length ? { immediateTools: immediate } : {}) }
23
24
  }
24
25
 
25
26
  /** WHAT A PRIVATE LANE TAKES FROM ITS SPACE: everything but the members (the owner, 2026-10-15: "the private lane inherits