@qvac/core 1.0.0-rc.2 → 1.0.0-rc.3

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 (195) hide show
  1. package/CHANGELOG.md +158 -2
  2. package/dist-lib/index.d.ts +1 -0
  3. package/dist-lib/index.js +1 -0
  4. package/dist-lib/lib/api/chunk-delta.d.ts +7 -2
  5. package/dist-lib/lib/api/chunk-delta.js +89 -7
  6. package/dist-lib/lib/api/chunks.js +14 -8
  7. package/dist-lib/lib/api/config.d.ts +4 -1
  8. package/dist-lib/lib/api/config.js +45 -4
  9. package/dist-lib/lib/api/custom-models.js +3 -5
  10. package/dist-lib/lib/api/devices.js +3 -1
  11. package/dist-lib/lib/api/files.d.ts +1 -1
  12. package/dist-lib/lib/api/files.js +65 -8
  13. package/dist-lib/lib/api/instrument.js +12 -4
  14. package/dist-lib/lib/api/members.js +7 -13
  15. package/dist-lib/lib/api/mesh.d.ts +1 -3
  16. package/dist-lib/lib/api/mesh.js +2 -2
  17. package/dist-lib/lib/api/notifications.js +8 -4
  18. package/dist-lib/lib/api/projects.js +5 -1
  19. package/dist-lib/lib/api/rag.js +32 -19
  20. package/dist-lib/lib/api/served.js +2 -1
  21. package/dist-lib/lib/api/workspace.js +0 -1
  22. package/dist-lib/lib/assistant/harness.d.ts +8 -2
  23. package/dist-lib/lib/assistant/harness.js +17 -4
  24. package/dist-lib/lib/assistant/history.d.ts +1 -1
  25. package/dist-lib/lib/assistant/history.js +19 -13
  26. package/dist-lib/lib/assistant/message.d.ts +6 -1
  27. package/dist-lib/lib/assistant/message.js +22 -2
  28. package/dist-lib/lib/assistant/model-round.d.ts +5 -0
  29. package/dist-lib/lib/assistant/model-round.js +46 -18
  30. package/dist-lib/lib/assistant/pdf-budget.d.ts +10 -2
  31. package/dist-lib/lib/assistant/pdf-budget.js +10 -11
  32. package/dist-lib/lib/assistant/pdf-pages.d.ts +25 -0
  33. package/dist-lib/lib/assistant/pdf-pages.js +75 -0
  34. package/dist-lib/lib/assistant/round-host.js +5 -3
  35. package/dist-lib/lib/assistant-client.d.ts +2 -1
  36. package/dist-lib/lib/assistant-client.js +24 -6
  37. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  38. package/dist-lib/lib/assistant-tree.js +8 -5
  39. package/dist-lib/lib/assistant.d.ts +20 -7
  40. package/dist-lib/lib/assistant.js +468 -240
  41. package/dist-lib/lib/client.js +10 -1
  42. package/dist-lib/lib/compaction.d.ts +3 -1
  43. package/dist-lib/lib/compaction.js +18 -4
  44. package/dist-lib/lib/constants.d.ts +3 -0
  45. package/dist-lib/lib/constants.js +3 -0
  46. package/dist-lib/lib/core/chat-activity.js +13 -16
  47. package/dist-lib/lib/core/chat-copy.js +1 -1
  48. package/dist-lib/lib/core/chat-fork.js +2 -1
  49. package/dist-lib/lib/core/chat-move.d.ts +4 -0
  50. package/dist-lib/lib/core/chat-move.js +42 -11
  51. package/dist-lib/lib/core/chat.d.ts +0 -1
  52. package/dist-lib/lib/core/chat.js +1 -1
  53. package/dist-lib/lib/core/chunk.d.ts +14 -3
  54. package/dist-lib/lib/core/chunk.js +112 -22
  55. package/dist-lib/lib/core/collections.d.ts +12 -1
  56. package/dist-lib/lib/core/collections.js +12 -1
  57. package/dist-lib/lib/core/config-value.d.ts +6 -0
  58. package/dist-lib/lib/core/config-value.js +14 -0
  59. package/dist-lib/lib/core/contract/activity.d.ts +3 -2
  60. package/dist-lib/lib/core/contract/activity.js +39 -21
  61. package/dist-lib/lib/core/contract/agent-join.js +15 -19
  62. package/dist-lib/lib/core/contract/agents.js +8 -7
  63. package/dist-lib/lib/core/contract/chat.d.ts +3 -0
  64. package/dist-lib/lib/core/contract/chat.js +12 -1
  65. package/dist-lib/lib/core/contract/chunks.js +16 -6
  66. package/dist-lib/lib/core/contract/devices.js +6 -4
  67. package/dist-lib/lib/core/contract/index.js +2 -1
  68. package/dist-lib/lib/core/contract/invites.js +12 -31
  69. package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
  70. package/dist-lib/lib/core/contract/mesh-rules.js +4 -0
  71. package/dist-lib/lib/core/contract/model-requests.js +7 -6
  72. package/dist-lib/lib/core/contract/project-device-keys.js +15 -6
  73. package/dist-lib/lib/core/contract/project-host-keys.js +5 -4
  74. package/dist-lib/lib/core/contract/projects.js +12 -13
  75. package/dist-lib/lib/core/contract/public-seeds.js +5 -5
  76. package/dist-lib/lib/core/contract/roles.js +2 -1
  77. package/dist-lib/lib/core/contract/run-requests.d.ts +1 -1
  78. package/dist-lib/lib/core/contract/run-requests.js +19 -13
  79. package/dist-lib/lib/core/contract/shipped-rows.d.ts +2 -0
  80. package/dist-lib/lib/core/contract/shipped-rows.js +22 -0
  81. package/dist-lib/lib/core/contract/workspace.js +4 -10
  82. package/dist-lib/lib/core/contract/writers.js +20 -6
  83. package/dist-lib/lib/core/devices.d.ts +2 -1
  84. package/dist-lib/lib/core/devices.js +4 -2
  85. package/dist-lib/lib/core/document-attachment.d.ts +6 -3
  86. package/dist-lib/lib/core/document-attachment.js +10 -5
  87. package/dist-lib/lib/core/files/attachments.js +3 -3
  88. package/dist-lib/lib/core/files/index.d.ts +8 -5
  89. package/dist-lib/lib/core/files/index.js +109 -18
  90. package/dist-lib/lib/core/files/processing/index.d.ts +1 -1
  91. package/dist-lib/lib/core/files/processing/index.js +8 -2
  92. package/dist-lib/lib/core/files/processing/source.d.ts +1 -0
  93. package/dist-lib/lib/core/files/processing/source.js +3 -0
  94. package/dist-lib/lib/core/files/processing/state.d.ts +1 -0
  95. package/dist-lib/lib/core/files/processing/state.js +7 -0
  96. package/dist-lib/lib/core/files/rag/build.d.ts +1 -0
  97. package/dist-lib/lib/core/files/rag/build.js +14 -1
  98. package/dist-lib/lib/core/files/rag/index.d.ts +1 -1
  99. package/dist-lib/lib/core/files/rag/index.js +1 -1
  100. package/dist-lib/lib/core/files/rag/produce.js +1 -0
  101. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +2 -0
  102. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +7 -1
  103. package/dist-lib/lib/core/first-event.d.ts +6 -0
  104. package/dist-lib/lib/core/first-event.js +13 -0
  105. package/dist-lib/lib/core/invite.d.ts +2 -2
  106. package/dist-lib/lib/core/invite.js +5 -4
  107. package/dist-lib/lib/core/local/index.d.ts +10 -1
  108. package/dist-lib/lib/core/local/index.js +105 -10
  109. package/dist-lib/lib/core/mesh.d.ts +15 -4
  110. package/dist-lib/lib/core/mesh.js +128 -57
  111. package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
  112. package/dist-lib/lib/core/migrations/chat-chunks.js +47 -0
  113. package/dist-lib/lib/core/migrations/file-index.d.ts +1 -1
  114. package/dist-lib/lib/core/migrations/file-index.js +6 -2
  115. package/dist-lib/lib/core/migrations/index.d.ts +2 -1
  116. package/dist-lib/lib/core/migrations/index.js +66 -9
  117. package/dist-lib/lib/core/notification.js +96 -23
  118. package/dist-lib/lib/core/pdf/figure.d.ts +22 -0
  119. package/dist-lib/lib/core/pdf/figure.js +64 -0
  120. package/dist-lib/lib/core/pdf/rasterize.d.ts +10 -1
  121. package/dist-lib/lib/core/pdf/rasterize.js +72 -22
  122. package/dist-lib/lib/core/peer-duplex.js +57 -5
  123. package/dist-lib/lib/core/public-mesh.js +8 -2
  124. package/dist-lib/lib/core/run-requests.js +2 -3
  125. package/dist-lib/lib/core/senders.d.ts +7 -6
  126. package/dist-lib/lib/core/senders.js +23 -30
  127. package/dist-lib/lib/core/shared-agents.d.ts +1 -0
  128. package/dist-lib/lib/core/shared-agents.js +47 -19
  129. package/dist-lib/lib/core/sync/background.d.ts +3 -15
  130. package/dist-lib/lib/core/sync/background.js +25 -102
  131. package/dist-lib/lib/core/sync/devices.js +6 -3
  132. package/dist-lib/lib/core/sync/index.js +12 -2
  133. package/dist-lib/lib/core/sync-status.js +3 -3
  134. package/dist-lib/lib/core.d.ts +59 -10
  135. package/dist-lib/lib/core.js +706 -174
  136. package/dist-lib/lib/credential-pusher.d.ts +11 -7
  137. package/dist-lib/lib/credential-pusher.js +40 -8
  138. package/dist-lib/lib/device-tree.d.ts +18 -0
  139. package/dist-lib/lib/device-tree.js +32 -0
  140. package/dist-lib/lib/doctor/redact.js +1 -1
  141. package/dist-lib/lib/errors.d.ts +4 -0
  142. package/dist-lib/lib/errors.js +4 -0
  143. package/dist-lib/lib/fs-drive-bridge.d.ts +7 -0
  144. package/dist-lib/lib/fs-drive-bridge.js +308 -30
  145. package/dist-lib/lib/integrations/setup-routes.js +7 -5
  146. package/dist-lib/lib/knowledge-search.d.ts +1 -1
  147. package/dist-lib/lib/knowledge-search.js +5 -46
  148. package/dist-lib/lib/kv-cache-retention.d.ts +35 -0
  149. package/dist-lib/lib/kv-cache-retention.js +98 -0
  150. package/dist-lib/lib/latest-frame.d.ts +10 -0
  151. package/dist-lib/lib/latest-frame.js +48 -0
  152. package/dist-lib/lib/model-download.d.ts +6 -1
  153. package/dist-lib/lib/model-download.js +32 -17
  154. package/dist-lib/lib/oauth/resolve.js +13 -5
  155. package/dist-lib/lib/reconnecting-watch.js +19 -11
  156. package/dist-lib/lib/run-notices.d.ts +2 -0
  157. package/dist-lib/lib/run-notices.js +5 -0
  158. package/dist-lib/lib/run-replay.d.ts +13 -1
  159. package/dist-lib/lib/run-replay.js +58 -21
  160. package/dist-lib/schema/build.js +66 -57
  161. package/dist-lib/schema/content.js +2 -1
  162. package/dist-lib/schema/engine.js +37 -5
  163. package/dist-lib/schema/field-order.js +7 -1
  164. package/dist-lib/schema/indexes.d.ts +4 -0
  165. package/dist-lib/schema/indexes.js +18 -0
  166. package/dist-lib/schema/local.js +9 -2
  167. package/dist-lib/schema/qvac.js +112 -4
  168. package/dist-lib/spec/bind.js +3 -0
  169. package/dist-lib/spec/calls.js +1 -0
  170. package/dist-lib/spec/capabilities.d.ts +2 -0
  171. package/dist-lib/spec/hrpc/hrpc.json +13 -0
  172. package/dist-lib/spec/hrpc/index.js +15 -3
  173. package/dist-lib/spec/hrpc/messages.js +1475 -1392
  174. package/dist-lib/spec/hyperschema/index.js +1475 -1392
  175. package/dist-lib/spec/hyperschema/schema.json +86 -1
  176. package/dist-lib/spec/hyperschema/types.d.ts +21 -1
  177. package/dist-lib/spec/local/hyperdb/messages.js +110 -54
  178. package/dist-lib/spec/local/hyperschema/index.js +56 -28
  179. package/dist-lib/spec/local/hyperschema/schema.json +55 -20
  180. package/dist-lib/spec/local/hyperschema/types.d.ts +8 -1
  181. package/dist-lib/spec/mesh/hyperdb/db.json +255 -51
  182. package/dist-lib/spec/mesh/hyperdb/index.js +1063 -404
  183. package/dist-lib/spec/mesh/hyperdb/messages.js +1647 -1214
  184. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +62 -56
  185. package/dist-lib/spec/mesh/hyperdispatch/index.js +156 -139
  186. package/dist-lib/spec/mesh/hyperdispatch/messages.js +787 -629
  187. package/dist-lib/spec/mesh/hyperschema/index.js +787 -629
  188. package/dist-lib/spec/mesh/hyperschema/schema.json +283 -174
  189. package/dist-lib/spec/mesh/hyperschema/types.d.ts +29 -1
  190. package/package.json +23 -17
  191. package/worker/assistant-sidecar.mjs +3 -0
  192. package/dist-lib/lib/core/files/processing/settle.d.ts +0 -13
  193. package/dist-lib/lib/core/files/processing/settle.js +0 -86
  194. package/dist-lib/lib/core/migrations/device-indexes.d.ts +0 -2
  195. package/dist-lib/lib/core/migrations/device-indexes.js +0 -7
@@ -18,6 +18,7 @@ import { writeAutoDownloadModels } from './api/app-config.js';
18
18
  import { requireOurAdmin, requireWorkspace } from './api/members.js';
19
19
  import { projectName } from './api/projects.js';
20
20
  import { createServedApi } from './api/served.js';
21
+ import { firstEvent } from './core/first-event.js';
21
22
  import { departedMembers, isWorkspace, lastAdminAmongOthers, liveMemberIds, readMemberKey, upgradeMembers } from './core/contract/workspace.js';
22
23
  import { readPublicSeed } from './core/contract/public-seeds.js';
23
24
  import { openSealedToDevice, sealToDevice } from './core/device-seal.js';
@@ -31,6 +32,7 @@ import { ChatMoves } from './core/chat-move.js';
31
32
  import { purgeCores } from './core/purge.js';
32
33
  import { copyContent } from './core/chat-copy.js';
33
34
  import { followAgentCopies, keepCopyChats } from './core/agent-copies.js';
35
+ import { devicesOfMember } from './core/contract/activity.js';
34
36
  import { followPickedAgents, followSharedAgents, liveSharedAgent, pickAgent, shareAgent, unpickAgent } from './core/shared-agents.js';
35
37
  import { inRole, publicRoute } from './core/contract/roles.js';
36
38
  import { freshPublicRecord, isOwnWorkspace, isPublicRecord, lostMint, onOwnSeed, leftPublicRecordKey, ownWorkspaceSeed, ownWorkspaces, publicMeshKey, publicRecordKey, publicSeed, servesAgents, servesChat, servesChunk } from './core/public-mesh.js';
@@ -63,13 +65,14 @@ import { openRecoveryCore, publishRecovery, readRecovery, recoveryKeys } from '.
63
65
  import { claimOwnMembership, legacyNameStamp, namedAt, renameFoundedMember } from './core/membership.js';
64
66
  import { runMigrations } from './core/migrations/index.js';
65
67
  import { backfillFileIndex } from './core/migrations/file-index.js';
68
+ import { REINDEX_FROM_APP_VERSION, backfillChatChunks, floorExcludesBefore } from './core/migrations/chat-chunks.js';
66
69
  import { advertiseDeviceVersion, retractInventory } from './core/devices.js';
67
70
  import { DeviceControl } from './core/device-control.js';
68
71
  import { forwardToDevices, servedToSiblings } from './api/device-routes.js';
69
72
  import { OtaConfigReader, configCoreFor, resolveConfigChannel, vendoredMinSupportedVersion } from './core/ota-config.js';
70
73
  import { updateRequired } from './core/min-version.js';
71
74
  import { PendingDepartures, waitForDelivery } from './core/departures.js';
72
- import { Mesh } from './core/mesh.js';
75
+ import { Mesh, SCHEMA_VERSION } from './core/mesh.js';
73
76
  import { raceResource } from './race-resource.js';
74
77
  import { createSystemInfoSampler } from './core/system-info.js';
75
78
  import { projectSenders } from './core/senders.js';
@@ -84,7 +87,6 @@ const top = new Top();
84
87
  const FILE_GC_INTERVAL_MS = 24 * 60 * 60 * 1000;
85
88
  const SWARM_KEYPAIR_NAME = 'qvac-swarm-keypair';
86
89
  const QVAC_CORE_NAMESPACE = 'qvac-core';
87
- const HELD_AGENTS_PREFIX = 'skill-values.held-agents';
88
90
  const MESH_ID = /^[0-9a-f]{64}$/;
89
91
  export const DEVICE_UNKNOWN = 'This device has no device details: pass `device` when creating Core';
90
92
  const RECOVERY_WAIT_MS = 30_000;
@@ -93,7 +95,9 @@ const MESH_DIED = 'the local database died';
93
95
  const MESH_NOT_EMPTY = 'this mesh is not empty: everyone in it will see the newcomer arrive, and the newcomer replays the whole history of the mesh, including what earlier members wrote';
94
96
  const INVITE_DHT_NODES_LIMIT = 3;
95
97
  const INVITE_BLIND_PEERS_LIMIT = 3;
98
+ const INVITE_PUBLIC_HEADS_LIMIT = 3;
96
99
  const DIAGNOSTICS_SAMPLE_MS = 2000;
100
+ const PUBLIC_FOLLOW_ATTEMPTS = 3;
97
101
  export class Core extends ReadyResource {
98
102
  _storagePath;
99
103
  store;
@@ -109,6 +113,7 @@ export class Core extends ReadyResource {
109
113
  _log;
110
114
  _spec;
111
115
  _bootstrapNodes;
116
+ _network;
112
117
  _device;
113
118
  _app;
114
119
  _minSupportedVersion;
@@ -124,7 +129,6 @@ export class Core extends ReadyResource {
124
129
  _blindPeerKeys;
125
130
  _blindPeeringOpts;
126
131
  _fileGc;
127
- _syncPacing;
128
132
  _autoDownloadModels;
129
133
  _fileGcTimer = null;
130
134
  _fileGcRun = null;
@@ -159,6 +163,7 @@ export class Core extends ReadyResource {
159
163
  _meshTransitionLock = new ScopeLock();
160
164
  _opening = new Map();
161
165
  _retiring = new Map();
166
+ _tearingDown = new Map();
162
167
  _debugBeforeMeshOpen;
163
168
  _debugOnMeshOpened;
164
169
  _skills;
@@ -201,6 +206,7 @@ export class Core extends ReadyResource {
201
206
  _groupPassesDue = new WeakSet();
202
207
  _purging = new Map();
203
208
  _publicIds = new Map();
209
+ _publicBoots = new Map();
204
210
  _meshNames = new Map();
205
211
  _ownWorkspaceId = null;
206
212
  _publicWriters = new WeakMap();
@@ -227,8 +233,12 @@ export class Core extends ReadyResource {
227
233
  _minting;
228
234
  _backfill = Promise.resolve();
229
235
  _leaving;
230
- _kicked;
231
- _kickedPending;
236
+ _kickedMeshes = new Set();
237
+ _kickCloses = new Map();
238
+ _retiredMeshes = new Set();
239
+ _retiredAccount = null;
240
+ _kickNotice = false;
241
+ _leaveChecks = null;
232
242
  _peers;
233
243
  _peerArrivedSuspended = false;
234
244
  _statusListeners;
@@ -243,7 +253,7 @@ export class Core extends ReadyResource {
243
253
  _systemInfo;
244
254
  _statusError;
245
255
  _upgradeRequired;
246
- constructor(transport, { storagePath, store = undefined, swarm = undefined, wakeup = undefined, logger = null, spec = openLocalSpec, bootstrapNodes = undefined, device = undefined, app = undefined, minSupportedVersion = undefined, otaConfigCore = undefined, blindPeerKeys = undefined, blindPeeringOpts = undefined, fileGc = null, autoDownloadModels = undefined, meshSeed = undefined, meshKey = undefined, additionalNodes = undefined, listModels = undefined, deleteModel = undefined, clearKvCache = undefined, deleteChatKvCache = undefined, compactChat = undefined, modelCatalogWatch = undefined, retryModelDownload = undefined, transcribe = undefined, detectLanguage = undefined, previewModelSource = undefined, speak = undefined, speakStream = undefined, embedder = undefined, extractors = undefined, skills = undefined, skillCatalog = undefined, tools = undefined, hostsModelSource = false, vectorIndex = undefined, apiLifecycle = undefined, syncBatch = undefined, syncPauseMs = undefined }) {
256
+ constructor(transport, { storagePath, store = undefined, swarm = undefined, wakeup = undefined, logger = null, spec = openLocalSpec, bootstrapNodes = undefined, device = undefined, app = undefined, minSupportedVersion = undefined, otaConfigCore = undefined, blindPeerKeys = undefined, blindPeeringOpts = undefined, fileGc = null, autoDownloadModels = undefined, meshSeed = undefined, meshKey = undefined, additionalNodes = undefined, listModels = undefined, deleteModel = undefined, clearKvCache = undefined, deleteChatKvCache = undefined, compactChat = undefined, modelCatalogWatch = undefined, retryModelDownload = undefined, transcribe = undefined, detectLanguage = undefined, previewModelSource = undefined, speak = undefined, speakStream = undefined, embedder = undefined, extractors = undefined, skills = undefined, skillCatalog = undefined, tools = undefined, hostsModelSource = false, vectorIndex = undefined, apiLifecycle = undefined, network = undefined }) {
247
257
  super();
248
258
  this._transport = transport;
249
259
  this._apiLifecycle = apiLifecycle ?? {
@@ -269,6 +279,7 @@ export class Core extends ReadyResource {
269
279
  this.state = QvacState.RESUME;
270
280
  this._spec = spec;
271
281
  this._bootstrapNodes = bootstrapNodes;
282
+ this._network = network;
272
283
  this._device = device;
273
284
  this._app = app;
274
285
  this._minSupportedVersion = minSupportedVersion;
@@ -282,7 +293,6 @@ export class Core extends ReadyResource {
282
293
  this._blindPeerKeys = blindPeerKeys;
283
294
  this._blindPeeringOpts = blindPeeringOpts;
284
295
  this._fileGc = fileGc;
285
- this._syncPacing = { syncBatch, syncPauseMs };
286
296
  this._autoDownloadModels = autoDownloadModels;
287
297
  this._meshSeed = meshSeed;
288
298
  this._meshKey = meshKey;
@@ -344,8 +354,6 @@ export class Core extends ReadyResource {
344
354
  this._servedToSiblings = null;
345
355
  this._minting = false;
346
356
  this._leaving = null;
347
- this._kicked = false;
348
- this._kickedPending = false;
349
357
  this._peers = new Map();
350
358
  this._statusListeners = new Set();
351
359
  this._senderListeners = new Set();
@@ -384,6 +392,12 @@ export class Core extends ReadyResource {
384
392
  return [...new Set(ids)].sort();
385
393
  }
386
394
  async _open() {
395
+ this._log?.info('lifecycle', 'core opening', {
396
+ app: this._app?.version ?? null,
397
+ build: this._app?.build ?? null,
398
+ channel: this._app?.channel ?? null,
399
+ schema: SCHEMA_VERSION
400
+ });
387
401
  this._runBootOffline().catch(noop);
388
402
  this._runBootOnline().catch(noop);
389
403
  await this._offlineBoot.ready();
@@ -397,10 +411,17 @@ export class Core extends ReadyResource {
397
411
  this._blindPeeringOn = (await this.local.get(BLIND_PEERING_OFF_KEY)) !== true;
398
412
  this._localDevice = await this.local.ensureDevice(this._deviceKeyPair.publicKey, this._device);
399
413
  await this.local.dropLeftMeshes();
400
- await this._retireComputeMeshes();
401
414
  for (const row of await this.local.meshNames()) {
402
415
  this._meshNames.set(b4a.toHex(row.meshKey), row);
403
416
  }
417
+ for (const row of await this.local.listMeshes()) {
418
+ if (row.kicked) {
419
+ this._kickedMeshes.add(b4a.toHex(row.key));
420
+ }
421
+ if (row.retiredUnder) {
422
+ this._retiredMeshes.add(b4a.toHex(row.key));
423
+ }
424
+ }
404
425
  this._resumePurges().catch((err) => this._log?.warn(['p2p', 'mesh'], 'reading the interrupted purges failed', err));
405
426
  if (this._autoDownloadModels !== undefined) {
406
427
  await writeAutoDownloadModels(this.local, this._autoDownloadModels);
@@ -705,14 +726,6 @@ export class Core extends ReadyResource {
705
726
  this._log?.error(['p2p', 'mesh'], 'mesh open failed', err);
706
727
  }
707
728
  }
708
- async _retireComputeMeshes() {
709
- for (const row of await this.local.listMeshes()) {
710
- if (row.compute) {
711
- await this._teardownMesh(row.key);
712
- }
713
- }
714
- await this.local.deletePrefix(HELD_AGENTS_PREFIX);
715
- }
716
729
  async _runBootOnline() {
717
730
  void this.onlineBoot.ready().catch(noop);
718
731
  try {
@@ -889,6 +902,9 @@ export class Core extends ReadyResource {
889
902
  if (withheld) {
890
903
  void this._reopenMesh();
891
904
  }
905
+ for (const { mesh } of this._meshes.values()) {
906
+ void this._backfillChatChunks(mesh);
907
+ }
892
908
  return;
893
909
  }
894
910
  for (const { mesh } of [...this._meshes.values()]) {
@@ -1143,6 +1159,10 @@ export class Core extends ReadyResource {
1143
1159
  bootstrap: this._bootstrapNodes,
1144
1160
  relayThrough: this._bootstrapNodes ? undefined : () => BLIND_RELAY_KEYS
1145
1161
  });
1162
+ const onConnection = this._network?.onConnection;
1163
+ if (onConnection) {
1164
+ this._swarm.on('connection', (conn) => onConnection(conn));
1165
+ }
1146
1166
  this._swarm.on('connection', this._onSwarmConnection);
1147
1167
  for (const conn of this._swarm.connections) {
1148
1168
  if (isPeerConnection(conn)) {
@@ -1211,7 +1231,7 @@ export class Core extends ReadyResource {
1211
1231
  this._joinProjectWhenListed(mesh, deviceId);
1212
1232
  }
1213
1233
  else {
1214
- void this._appendJoinLater(mesh, () => this._knownBirthMember(mesh, deviceId), sharing);
1234
+ void this._appendJoinLater(mesh, () => this._ownBirthMember(mesh, deviceId), sharing);
1215
1235
  }
1216
1236
  }
1217
1237
  else {
@@ -1248,7 +1268,7 @@ export class Core extends ReadyResource {
1248
1268
  attachmentUrl: (attachment) => this._linkAttachment(attachment, mesh),
1249
1269
  fileIndex: this._fileIndexFor(() => mesh),
1250
1270
  pendingUpdates: this._pendingUpdatesFor(() => mesh),
1251
- ...this._syncPacing
1271
+ bootFrom: session.bootFrom
1252
1272
  });
1253
1273
  return mesh;
1254
1274
  }
@@ -1578,6 +1598,20 @@ export class Core extends ReadyResource {
1578
1598
  proof
1579
1599
  };
1580
1600
  }
1601
+ async _ownBirthMember(mesh, deviceId) {
1602
+ const account = this._accountMesh();
1603
+ while (account && account !== mesh && !account.ourMemberId) {
1604
+ if (this.closing || mesh.closing || account.closing) {
1605
+ return null;
1606
+ }
1607
+ await firstEvent([
1608
+ [account, 'membership'],
1609
+ [account, 'close'],
1610
+ [mesh, 'close']
1611
+ ]);
1612
+ }
1613
+ return this._knownBirthMember(mesh, deviceId);
1614
+ }
1581
1615
  async _knownBirthMember(mesh, deviceId, given) {
1582
1616
  if (!this._localDevice || mesh.localLength > 0)
1583
1617
  return null;
@@ -1696,6 +1730,11 @@ export class Core extends ReadyResource {
1696
1730
  if (this._swarm) {
1697
1731
  if (announce) {
1698
1732
  this._swarm.join(mesh.discoveryKey, { server: true, client: true });
1733
+ this._network?.onMeshTopic?.({
1734
+ meshId: this._meshIdOf(mesh),
1735
+ topic: mesh.discoveryKey,
1736
+ swarm: this._swarm
1737
+ });
1699
1738
  }
1700
1739
  this._startBlindPeering(mesh);
1701
1740
  if (this.suspended) {
@@ -1881,10 +1920,20 @@ export class Core extends ReadyResource {
1881
1920
  }
1882
1921
  }
1883
1922
  async _knownMember(exclude) {
1884
- for (const entry of this._meshes.values()) {
1885
- if (entry.mesh === exclude || !entry.mesh.ourMemberId)
1923
+ const account = this._accountMesh();
1924
+ if (account && account !== exclude && account.ourMemberId) {
1925
+ const known = await this._memberIn(account).catch(noop);
1926
+ if (known) {
1927
+ return known;
1928
+ }
1929
+ }
1930
+ for (const { mesh } of this._meshes.values()) {
1931
+ if (mesh === exclude ||
1932
+ !mesh.ourMemberId ||
1933
+ this._isHidden(this._meshIdOf(mesh), mesh.workspaceKey)) {
1886
1934
  continue;
1887
- const known = await this._memberIn(entry.mesh).catch(noop);
1935
+ }
1936
+ const known = await this._memberIn(mesh).catch(noop);
1888
1937
  if (known) {
1889
1938
  return known;
1890
1939
  }
@@ -1943,22 +1992,21 @@ export class Core extends ReadyResource {
1943
1992
  async _ensureNotRevoked(mesh) {
1944
1993
  const wasAccount = this._isAccount(mesh);
1945
1994
  try {
1946
- const revocation = (await mesh.checkResumedRevocation()) ?? ((await mesh.ownWriterRefused()) ? 'kicked' : null);
1995
+ let revocation = await mesh.checkResumedRevocation();
1996
+ if (!revocation && (await mesh.checkResumedRefusal())) {
1997
+ revocation = 'kicked';
1998
+ }
1947
1999
  if (!revocation || !this._isPooled(mesh)) {
1948
2000
  return;
1949
2001
  }
1950
- if (!wasAccount || !this._isAccount(mesh)) {
1951
- if (revocation !== 'kicked') {
1952
- return;
1953
- }
1954
- this._log?.info(['p2p', 'mesh'], 'a sibling mesh kicked this device, closing it');
1955
- await this._departKicked(mesh);
2002
+ if (revocation === 'kicked') {
2003
+ await this._reviewKick(mesh);
1956
2004
  return;
1957
2005
  }
1958
- this._log?.info(['p2p', 'mesh'], `resumed already revoked (${revocation} while offline), replacing the account`);
1959
- if (revocation === 'kicked') {
1960
- this._kickedPending = true;
2006
+ if (!wasAccount || !this._isAccount(mesh)) {
2007
+ return;
1961
2008
  }
2009
+ this._log?.info(['p2p', 'mesh'], 'resumed onto our own leave, replacing the account');
1962
2010
  await this._replaceRevokedAccount(mesh);
1963
2011
  }
1964
2012
  catch (err) {
@@ -1997,7 +2045,17 @@ export class Core extends ReadyResource {
1997
2045
  await this._retireMesh(mesh);
1998
2046
  }
1999
2047
  }
2000
- async _teardownMesh(target, { depart = false, purge = false } = {}) {
2048
+ _teardownMesh(target, opts = {}) {
2049
+ const meshId = b4a.toHex(b4a.isBuffer(target) ? target : target.key);
2050
+ const teardown = this._tearDown(target, opts).finally(() => {
2051
+ if (this._tearingDown.get(meshId) === teardown) {
2052
+ this._tearingDown.delete(meshId);
2053
+ }
2054
+ });
2055
+ this._tearingDown.set(meshId, teardown);
2056
+ return teardown;
2057
+ }
2058
+ async _tearDown(target, { depart = false, purge = false }) {
2001
2059
  const key = b4a.isBuffer(target) ? target : target.key;
2002
2060
  const mesh = b4a.isBuffer(target) ? this._pooled(b4a.toHex(key)) : target;
2003
2061
  if (mesh && depart) {
@@ -2013,6 +2071,7 @@ export class Core extends ReadyResource {
2013
2071
  finally {
2014
2072
  await this.local.dropMesh(key, { keepDeparture: true, cores });
2015
2073
  this._meshNames.delete(b4a.toHex(key));
2074
+ this._kickedMeshes.delete(b4a.toHex(key));
2016
2075
  this._notifyStatus();
2017
2076
  }
2018
2077
  if (cores) {
@@ -2050,27 +2109,217 @@ export class Core extends ReadyResource {
2050
2109
  this._log?.warn(['p2p', 'mesh'], 'retiring the stalled mesh failed', retireErr);
2051
2110
  });
2052
2111
  }
2053
- _onKicked(mesh) {
2054
- if (this.closing || this._leaving)
2112
+ async _reviewKick(mesh) {
2113
+ const entry = this._meshes.get(this._meshIdOf(mesh));
2114
+ if (entry?.mesh !== mesh || !(await entry.kickLock.lock())) {
2055
2115
  return;
2056
- if (!this._isAccount(mesh)) {
2057
- this._log?.info(['p2p', 'mesh'], 'our writer was revoked on a sibling mesh, closing it');
2058
- this._departKicked(mesh).catch((err) => this._log?.warn(['p2p', 'mesh'], 'closing the revoked sibling mesh failed', err));
2116
+ }
2117
+ try {
2118
+ const kicked = await this._readKick(mesh).catch(noop);
2119
+ const id = this._meshIdOf(mesh);
2120
+ if (kicked === undefined || this.closing || !this._isPooled(mesh)) {
2121
+ return;
2122
+ }
2123
+ if (kicked && !this._kickedMeshes.has(id)) {
2124
+ await this._onKicked(mesh);
2125
+ }
2126
+ else if (!kicked && this._retiredAccount === id) {
2127
+ await this._onKickVoided(mesh);
2128
+ }
2129
+ }
2130
+ catch (err) {
2131
+ this._log?.warn(['p2p', 'mesh'], 'reviewing our kick failed', err);
2132
+ }
2133
+ finally {
2134
+ entry.kickLock.unlock();
2135
+ }
2136
+ }
2137
+ async _onKicked(mesh) {
2138
+ if (!(await this._kickOutlivesTransition(mesh))) {
2139
+ return;
2140
+ }
2141
+ const id = this._meshIdOf(mesh);
2142
+ this._log?.info(['p2p', 'mesh'], 'our writer was revoked (kicked)');
2143
+ this._kickedMeshes.add(id);
2144
+ if (this._isAccount(mesh)) {
2145
+ this._kickNotice = true;
2146
+ await this._retireKickedAccount(mesh);
2147
+ return;
2148
+ }
2149
+ const closing = this._noteKickedProject(mesh)
2150
+ .then(() => this._closeKicked(mesh))
2151
+ .catch((err) => this._log?.warn(['p2p', 'mesh'], 'closing a kicked mesh failed', err))
2152
+ .finally(() => this._kickCloses.delete(id));
2153
+ this._kickCloses.set(id, closing);
2154
+ this._notifyStatus();
2155
+ }
2156
+ async _kickOutlivesTransition(mesh) {
2157
+ if (!(await this._meshTransitionLock.lock())) {
2158
+ return false;
2159
+ }
2160
+ try {
2161
+ const kicked = await this._readKick(mesh).catch(noop);
2162
+ return kicked === true && !this.closing && this._isPooled(mesh);
2163
+ }
2164
+ finally {
2165
+ this._meshTransitionLock.unlock();
2166
+ }
2167
+ }
2168
+ async _onKickVoided(account) {
2169
+ this._log?.info(['p2p', 'mesh'], 'our kick was voided');
2170
+ this._kickedMeshes.delete(this._meshIdOf(account));
2171
+ this._kickNotice = false;
2172
+ this._notifyStatus();
2173
+ await this._restoreAccount(account);
2174
+ }
2175
+ async _readKick(mesh) {
2176
+ return (await mesh.readKicked()) || (await this._removedAsMember(mesh));
2177
+ }
2178
+ async _removedAsMember(mesh) {
2179
+ if (mesh.role !== 'workspace' || mesh.writable) {
2180
+ return false;
2181
+ }
2182
+ if ((await this.local.meshRecord(mesh.key))?.awaitingAdmission) {
2183
+ return false;
2184
+ }
2185
+ const account = this._accountMesh();
2186
+ const joined = await account?.view.get(JOINED_MESHES, { meshKey: mesh.key });
2187
+ const ours = account?.ourMemberId;
2188
+ if (!joined || joined.leftAt || !ours || !b4a.equals(joined.memberId, ours)) {
2189
+ return false;
2190
+ }
2191
+ const devices = await devicesOfMember(mesh.view, joined.memberId);
2192
+ return devices.length > 0 && devices.every((device) => device.revoked);
2193
+ }
2194
+ async _followKick(meshId, held) {
2195
+ if (this._kickedMeshes.has(meshId)) {
2196
+ return;
2197
+ }
2198
+ const key = b4a.from(meshId, 'hex');
2199
+ if (!held && !(await this.local.readMeshSession(key))) {
2200
+ return;
2201
+ }
2202
+ this._kickedMeshes.add(meshId);
2203
+ if (held) {
2204
+ await this._closeKicked(held);
2205
+ return;
2206
+ }
2207
+ await this.local.markKicked(key);
2208
+ for (const row of await this._projectRowsOf(key)) {
2209
+ this._kickedMeshes.add(b4a.toHex(row.key));
2210
+ await this.local.markKicked(row.key);
2211
+ }
2212
+ this._notifyStatus();
2213
+ }
2214
+ async _markJoinedKicked(meshKey) {
2215
+ const registry = await this._writableAccount();
2216
+ const joined = await registry?.view.get(JOINED_MESHES, { meshKey });
2217
+ if (!registry || !joined || joined.kicked || joined.leftAt) {
2218
+ return;
2219
+ }
2220
+ const joinedUnder = await this.local.joinedUnder(meshKey);
2221
+ if (joinedUnder !== null && joined.joinedAt > joinedUnder) {
2222
+ return;
2223
+ }
2224
+ await registry.dispatch('put-joined-mesh', { room: { ...joined, kicked: true } });
2225
+ }
2226
+ async _closeKicked(mesh) {
2227
+ if (await this._removedAsMember(mesh)) {
2228
+ await this._markJoinedKicked(mesh.key);
2229
+ }
2230
+ const projects = mesh.role === 'workspace' ? await this._projectRowsOf(mesh.key) : [];
2231
+ for (const row of [{ key: mesh.key }, ...projects]) {
2232
+ this._kickedMeshes.add(b4a.toHex(row.key));
2233
+ await this.local.markKicked(row.key);
2234
+ const pooled = this._pooled(b4a.toHex(row.key));
2235
+ if (pooled) {
2236
+ await this._retirePooledMesh(pooled);
2237
+ }
2238
+ }
2239
+ this._notifyStatus();
2240
+ const account = this._accountMesh();
2241
+ if (account && account !== mesh) {
2242
+ void this._followJoinedMeshes(account);
2243
+ }
2244
+ }
2245
+ async _projectRowsOf(workspaceKey) {
2246
+ return (await this.local.listMeshes()).filter((row) => row.workspaceKey && b4a.equals(row.workspaceKey, workspaceKey));
2247
+ }
2248
+ _isHidden(meshId, workspaceKey) {
2249
+ if (meshId === this._accountId) {
2250
+ return false;
2251
+ }
2252
+ if (this._kickedMeshes.has(meshId) || this._retiredMeshes.has(meshId)) {
2253
+ return true;
2254
+ }
2255
+ return !!workspaceKey && this._kickedMeshes.has(b4a.toHex(workspaceKey));
2256
+ }
2257
+ async _retireKickedAccount(account) {
2258
+ this._minting = true;
2259
+ this._notifyStatus();
2260
+ try {
2261
+ const retired = (await this.local.listMeshes()).filter((row) => !b4a.equals(row.key, account.key));
2262
+ for (const row of retired) {
2263
+ this._retiredMeshes.add(b4a.toHex(row.key));
2264
+ }
2265
+ await this.local.markRetired(retired.map((row) => row.key), account.key);
2266
+ this._retiredAccount = this._meshIdOf(account);
2267
+ await this._archiveMembership(account);
2268
+ await this._rotatePublicWriters(account);
2269
+ this._accountId = null;
2270
+ this._ownWorkspaceId = null;
2271
+ }
2272
+ finally {
2273
+ this._minting = false;
2274
+ }
2275
+ await this._requestFreshMesh();
2276
+ }
2277
+ async _restoreAccount(account) {
2278
+ if (this._minting) {
2279
+ await this._waitForMeshChange();
2280
+ }
2281
+ const fresh = this._accountMesh();
2282
+ if (this.closing ||
2283
+ !this._isPooled(account) ||
2284
+ this._retiredAccount !== this._meshIdOf(account)) {
2059
2285
  return;
2060
2286
  }
2061
- this._log?.info(['p2p', 'mesh'], 'our writer was revoked (kicked), replacing the account');
2062
- this._kicked = true;
2063
- this._kickedPending = true;
2064
- this._replaceRevokedAccount(mesh).catch((err) => this._log?.error(['p2p', 'mesh'], 'kick-driven replacement failed', err));
2287
+ this._retiredAccount = null;
2288
+ this._retiredMeshes.clear();
2289
+ await this.local.restoreMesh(account.key);
2290
+ await this._restorePublicWriters(account);
2291
+ await this._adoptAccount(account);
2292
+ if (fresh && fresh !== account) {
2293
+ await this._dropOwnMint(fresh);
2294
+ await this._teardownMesh(fresh, { purge: true });
2295
+ }
2296
+ }
2297
+ async _dropOwnMint(fresh) {
2298
+ const seed = ownWorkspaceSeed(fresh.seed);
2299
+ for (const row of await this.local.listMeshes()) {
2300
+ if (!b4a.equals(row.seed, seed)) {
2301
+ continue;
2302
+ }
2303
+ const id = b4a.toHex(row.key);
2304
+ const own = this._publicMesh(id);
2305
+ if (own) {
2306
+ await this._teardownMesh(own, { purge: true });
2307
+ }
2308
+ await this._teardownMesh(this._pooled(id) ?? (await this._openPooledMesh(id, 'leave')), {
2309
+ purge: true
2310
+ });
2311
+ }
2065
2312
  }
2066
2313
  async _replaceRevokedAccount(mesh) {
2067
2314
  this._minting = true;
2068
2315
  this._notifyStatus();
2069
2316
  try {
2317
+ await this._leaveKicked(mesh);
2070
2318
  await this._departAllBut(mesh);
2071
2319
  if (this.closing) {
2072
2320
  return;
2073
2321
  }
2322
+ await this._leavePublicMesh(mesh);
2074
2323
  await this._archiveMembership(mesh);
2075
2324
  }
2076
2325
  finally {
@@ -2078,21 +2327,56 @@ export class Core extends ReadyResource {
2078
2327
  }
2079
2328
  await this._requestFreshMesh();
2080
2329
  }
2330
+ async _leaveKicked(mesh) {
2331
+ try {
2332
+ await mesh.dispatch('remove-writer', {
2333
+ writerKey: mesh.localWriterKey,
2334
+ deviceId: this._requireDeviceKeyPair().publicKey,
2335
+ revokedAt: Date.now()
2336
+ }, { optimistic: true });
2337
+ await this.local.recordDeparture(mesh.key, { creator: mesh.minted });
2338
+ }
2339
+ catch (err) {
2340
+ this._log?.warn(['p2p', 'mesh'], 'writing our own leave after a kick failed', err);
2341
+ }
2342
+ }
2081
2343
  async _departKicked(mesh) {
2082
2344
  const ours = mesh.ourMemberId;
2083
2345
  if (ours && mesh.role === 'workspace' && !(await liveMember(mesh.view, ours))) {
2084
- await this._releaseJoinedMesh(mesh.key);
2346
+ await this._releaseJoinedMesh(mesh.key, undefined, await this.local.joinedUnder(mesh.key));
2085
2347
  }
2086
- let purge = false;
2087
- if (ours && mesh.role === 'project' && !(await inProject(mesh.view, ours))) {
2088
- const record = await this.local.meshRecord(mesh.key);
2089
- const workspace = record?.workspaceKey ? this._pooled(b4a.toHex(record.workspaceKey)) : null;
2090
- const row = await workspace?.view.get(PROJECTS, { id: mesh.key });
2091
- this._kickedProjects.set(this._meshIdOf(mesh), row && listsMember(row, ours) ? workspace : null);
2092
- purge = record?.role === 'project' && !!record.workspaceKey;
2348
+ if (mesh.role === 'workspace') {
2349
+ await this._departProjectsOf(mesh);
2093
2350
  }
2351
+ await this._noteKickedProject(mesh);
2352
+ const record = await this.local.meshRecord(mesh.key);
2353
+ const purge = record?.role === 'project' && !!record.workspaceKey;
2094
2354
  await this._departRevokedMesh(mesh, { purge });
2095
2355
  }
2356
+ async _noteKickedProject(mesh) {
2357
+ const ours = mesh.ourMemberId;
2358
+ if (!ours || mesh.role !== 'project' || (await inProject(mesh.view, ours))) {
2359
+ return false;
2360
+ }
2361
+ const record = await this.local.meshRecord(mesh.key);
2362
+ const workspace = record?.workspaceKey ? this._pooled(b4a.toHex(record.workspaceKey)) : null;
2363
+ const row = await workspace?.view.get(PROJECTS, { id: mesh.key });
2364
+ this._kickedProjects.set(this._meshIdOf(mesh), row && listsMember(row, ours) ? workspace : null);
2365
+ return record?.role === 'project' && !!record.workspaceKey;
2366
+ }
2367
+ async _departProjectsOf(workspace) {
2368
+ for (const row of await this.local.listMeshes()) {
2369
+ const ofWorkspace = row.workspaceKey && b4a.equals(row.workspaceKey, workspace.key);
2370
+ if (this.closing || !ofWorkspace || recordedRole(row) !== 'project') {
2371
+ continue;
2372
+ }
2373
+ this._kickedProjects.set(b4a.toHex(row.key), null);
2374
+ const project = await this._heldMesh(row.key, 'leave');
2375
+ await (project
2376
+ ? this._departRevokedMesh(project, { purge: true })
2377
+ : this._teardownMesh(row.key));
2378
+ }
2379
+ }
2096
2380
  async _departRevokedMesh(mesh, opts = {}) {
2097
2381
  const account = this._accountMesh();
2098
2382
  if (this._isOwnPublic(mesh) && mesh.workspaceKey && account) {
@@ -2164,9 +2448,6 @@ export class Core extends ReadyResource {
2164
2448
  if (!invite) {
2165
2449
  throw new CoreError('INVITE_INVALID');
2166
2450
  }
2167
- if (invite.compute) {
2168
- throw new CoreError('COMPUTE_MESH_RETIRED');
2169
- }
2170
2451
  await this._awaitMesh();
2171
2452
  this._requireLocalDevice();
2172
2453
  await this._meshTransitionLock.lock();
@@ -2178,8 +2459,24 @@ export class Core extends ReadyResource {
2178
2459
  if (this._leaving || this._minting) {
2179
2460
  throw new CoreError('MESH_TRANSITION_IN_PROGRESS');
2180
2461
  }
2181
- await this._opening.get(b4a.toHex(invite.baseKey))?.catch(noop);
2182
- const pooled = this._pooled(b4a.toHex(invite.baseKey));
2462
+ const meshId = b4a.toHex(invite.baseKey);
2463
+ await this._tearingDown.get(meshId)?.catch(noop);
2464
+ await this._opening.get(meshId)?.catch(noop);
2465
+ await this._kickCloses.get(meshId);
2466
+ const workspaceKey = this._pooled(meshId)?.workspaceKey;
2467
+ if (workspaceKey) {
2468
+ await this._kickCloses.get(b4a.toHex(workspaceKey));
2469
+ }
2470
+ let pooled = this._pooled(meshId);
2471
+ if (this._isHidden(meshId, pooled?.workspaceKey)) {
2472
+ if (pooled) {
2473
+ await this._teardownMesh(pooled, { depart: true, purge: true });
2474
+ }
2475
+ else {
2476
+ await this._dropKickedCopy(meshId);
2477
+ }
2478
+ pooled = null;
2479
+ }
2183
2480
  if (pooled?.writable) {
2184
2481
  if (!invite.memberInvite && !this._isAccount(pooled)) {
2185
2482
  await this._adoptAccount(pooled);
@@ -2262,6 +2559,7 @@ export class Core extends ReadyResource {
2262
2559
  if (retire) {
2263
2560
  await this._retirePooledMesh(retire);
2264
2561
  }
2562
+ await this._purging.get(meshId)?.catch(noop);
2265
2563
  await this._runJoinMesh(invite, claim);
2266
2564
  }
2267
2565
  catch (error) {
@@ -2315,6 +2613,9 @@ export class Core extends ReadyResource {
2315
2613
  for (const node of invite.additionalNodes ?? []) {
2316
2614
  this._swarm?.dht.addNode(node);
2317
2615
  }
2616
+ if (!invite.memberInvite) {
2617
+ this._publicBoots = new Map((invite.publicHeads ?? []).map(({ meshKey, head }) => [b4a.toHex(meshKey), head]));
2618
+ }
2318
2619
  await this._departures?.park(invite.baseKey);
2319
2620
  try {
2320
2621
  await this._joinParkedMesh(invite, claim, { source, deviceId });
@@ -2332,9 +2633,9 @@ export class Core extends ReadyResource {
2332
2633
  claim.reject(new CoreError('MESH_BELOW_FLOOR'));
2333
2634
  }
2334
2635
  }
2335
- _candidateSession({ seed, baseKey, workspace }) {
2636
+ _candidateSession({ seed, baseKey, workspace, fastForward }) {
2336
2637
  const role = workspace ? 'workspace' : undefined;
2337
- return this.local.createCandidateSession(seed, baseKey, { role });
2638
+ return { ...this.local.createCandidateSession(seed, baseKey, { role }), bootFrom: fastForward };
2338
2639
  }
2339
2640
  async _joinCandidate(invite, source, deviceId) {
2340
2641
  const session = this._candidateSession(invite);
@@ -2523,7 +2824,14 @@ export class Core extends ReadyResource {
2523
2824
  }
2524
2825
  const buckets = await this._groupBuckets(workspace);
2525
2826
  const rows = await projectsByGroup(workspace.view);
2526
- const settled = await Promise.all(buckets.map((bucket) => this._passGroup(workspace, ours, { bucket, row: rows.get(bucket.groupId) ?? null })));
2827
+ const passes = await Promise.allSettled(buckets.map((bucket) => this._passGroup(workspace, ours, { bucket, row: rows.get(bucket.groupId) ?? null })));
2828
+ const settled = [];
2829
+ for (const pass of passes) {
2830
+ if (pass.status === 'rejected') {
2831
+ throw pass.reason;
2832
+ }
2833
+ settled.push(pass.value);
2834
+ }
2527
2835
  if (settled.every((state) => state === 'done') && this._isPooled(workspace)) {
2528
2836
  await this.local.set(upgradeCheckedKey(workspace.key), true);
2529
2837
  }
@@ -2695,7 +3003,7 @@ export class Core extends ReadyResource {
2695
3003
  await workspace.dispatch('set-project-listing', { projectId: row.id, memberId });
2696
3004
  }
2697
3005
  }
2698
- if (added.length > 0) {
3006
+ if (added.length > 0 && this._isPooled(workspace)) {
2699
3007
  const listedMembers = [...listed, ...added.map((id) => b4a.toHex(id))];
2700
3008
  await this.local.set(recordKey, { ...record, listedMembers });
2701
3009
  }
@@ -2773,7 +3081,7 @@ export class Core extends ReadyResource {
2773
3081
  const { shared, workspace = false } = opts;
2774
3082
  const registry = opts.registry ?? (await this._writableAccount());
2775
3083
  const ours = registry?.ourMemberId;
2776
- if (!registry || !ours) {
3084
+ if (!registry || !ours || this._isHidden(b4a.toHex(meshKey))) {
2777
3085
  return;
2778
3086
  }
2779
3087
  const now = Date.now();
@@ -2787,6 +3095,7 @@ export class Core extends ReadyResource {
2787
3095
  workspace
2788
3096
  }
2789
3097
  });
3098
+ await this.local.markJoinedUnder(meshKey, now);
2790
3099
  await this._backfillMeshSeeds(registry).catch((err) => {
2791
3100
  this._log?.warn(['p2p', 'mesh'], 'writing the mesh seed failed; writable or settle retries', err);
2792
3101
  });
@@ -2818,7 +3127,9 @@ export class Core extends ReadyResource {
2818
3127
  const registered = new Set();
2819
3128
  const now = Date.now();
2820
3129
  for (const row of await this.local.listMeshes()) {
2821
- if (b4a.equals(row.key, account.key) || row.workspaceKey) {
3130
+ if (b4a.equals(row.key, account.key) ||
3131
+ row.workspaceKey ||
3132
+ this._isHidden(b4a.toHex(row.key))) {
2822
3133
  continue;
2823
3134
  }
2824
3135
  const held = await account.view.get(JOINED_MESHES, { meshKey: row.key });
@@ -2833,9 +3144,10 @@ export class Core extends ReadyResource {
2833
3144
  joinedAt: now,
2834
3145
  shared: false,
2835
3146
  sharedAt: 0,
2836
- workspace: !!pooled && (await isWorkspace(pooled.view))
3147
+ workspace: row.role === 'workspace' || (!!pooled && (await isWorkspace(pooled.view)))
2837
3148
  }
2838
3149
  });
3150
+ await this.local.markJoinedUnder(row.key, now);
2839
3151
  registered.add(b4a.toHex(row.key));
2840
3152
  }
2841
3153
  return registered;
@@ -2853,7 +3165,7 @@ export class Core extends ReadyResource {
2853
3165
  const held = await account.view.get(MESH_SEEDS, { meshKey: mesh.key });
2854
3166
  return !held || !b4a.equals(held.seed, mesh.seed);
2855
3167
  }
2856
- async _releaseJoinedMesh(meshKey, registry) {
3168
+ async _releaseJoinedMesh(meshKey, registry, joinedUnder) {
2857
3169
  try {
2858
3170
  const held = registry ? [registry] : [...this._meshes.values()].map((entry) => entry.mesh);
2859
3171
  for (const mesh of held) {
@@ -2866,7 +3178,12 @@ export class Core extends ReadyResource {
2866
3178
  continue;
2867
3179
  }
2868
3180
  await mesh.dispatch('put-joined-mesh', {
2869
- room: { meshKey, memberId: ours, joinedAt: joined.joinedAt, leftAt: Date.now() }
3181
+ room: {
3182
+ meshKey,
3183
+ memberId: ours,
3184
+ joinedAt: joinedUnder ?? joined.joinedAt,
3185
+ leftAt: Date.now()
3186
+ }
2870
3187
  });
2871
3188
  return;
2872
3189
  }
@@ -2906,13 +3223,12 @@ export class Core extends ReadyResource {
2906
3223
  writerSeed: session.writerSeed,
2907
3224
  logger: this._log,
2908
3225
  blindPeerKeys: this._resolveBlindPeerKeys(invite.blindPeers),
2909
- bootFrom: invite.fastForward,
3226
+ bootFrom: session.bootFrom,
2910
3227
  trustedDevice: (deviceId) => this._isOurMemberDevice(deviceId),
2911
3228
  wakeup: this._wakeup,
2912
3229
  attachmentUrl: (attachment) => this._linkAttachment(attachment, candidate),
2913
3230
  fileIndex: this._fileIndexFor(() => candidate),
2914
- pendingUpdates: this._pendingUpdatesFor(() => candidate),
2915
- ...this._syncPacing
3231
+ pendingUpdates: this._pendingUpdatesFor(() => candidate)
2916
3232
  });
2917
3233
  this._candidateMesh = candidate;
2918
3234
  if (this._swarm) {
@@ -3017,7 +3333,6 @@ export class Core extends ReadyResource {
3017
3333
  this._onProjectWritable(mesh);
3018
3334
  this._onSharedWritable(mesh);
3019
3335
  if (this._isAccount(mesh)) {
3020
- this._kicked = false;
3021
3336
  void this._followPublicMesh(mesh);
3022
3337
  void this._followSkillSecrets();
3023
3338
  }
@@ -3065,7 +3380,7 @@ export class Core extends ReadyResource {
3065
3380
  peer: () => this._notifyStatus()
3066
3381
  };
3067
3382
  entry.handlers = handlers;
3068
- mesh.on('kicked', () => this._onKicked(mesh));
3383
+ mesh.on('kick-dirty', () => this._reviewKick(mesh).catch((err) => this._log?.warn(['p2p', 'mesh'], 'reviewing a kick failed', err)));
3069
3384
  mesh.on('unattested-device', () => void this._settleMembership(mesh));
3070
3385
  if (mesh.writable) {
3071
3386
  this._onMeshSeedDue(mesh);
@@ -3078,6 +3393,7 @@ export class Core extends ReadyResource {
3078
3393
  }
3079
3394
  });
3080
3395
  mesh.on('members-dirty', () => void this._deviceControl.revalidate());
3396
+ mesh.on('members-dirty', () => void this._revokeInMeshes());
3081
3397
  mesh.on('members-dirty', () => {
3082
3398
  if (mesh.role !== 'workspace')
3083
3399
  return;
@@ -3106,30 +3422,15 @@ export class Core extends ReadyResource {
3106
3422
  if (!this._isAccount(mesh))
3107
3423
  return;
3108
3424
  void this._followAccountName(mesh);
3109
- void this._revokeInMeshes();
3110
- });
3111
- mesh.on('meshes-dirty', (changed, groupsChanged = false) => {
3112
- if (changed || entry.meshesPending) {
3113
- void this._followJoinedMeshes(mesh);
3114
- }
3115
- if (changed && mesh.role === 'workspace') {
3116
- void this._followProjects(mesh);
3117
- void this._followHosting();
3118
- }
3119
- if (mesh.role === 'project') {
3120
- void this._followUpgrade(mesh);
3121
- }
3122
- if ((changed || groupsChanged) && mesh.role === 'workspace') {
3123
- this._followGroups(mesh);
3124
- }
3125
- if (this._isAccount(mesh) && (changed || !this._publicMesh())) {
3126
- void this._followPublicMesh(mesh);
3127
- }
3128
3425
  });
3426
+ mesh.on('meshes-dirty', (changed, groupsChanged = false) => this._onMeshesDirty(entry, { changed, groupsChanged }));
3129
3427
  mesh.on('joined', () => {
3130
3428
  if (entry.meshesPending) {
3131
3429
  void this._followJoinedMeshes(mesh);
3132
3430
  }
3431
+ if (entry.publicPending) {
3432
+ void this._followPublicMesh(mesh);
3433
+ }
3133
3434
  });
3134
3435
  mesh.on('membership-tallied', () => this._notifyStatus());
3135
3436
  mesh.on('mesh-named', () => {
@@ -3137,6 +3438,8 @@ export class Core extends ReadyResource {
3137
3438
  this._notifyStatus();
3138
3439
  });
3139
3440
  mesh.on('membership', (membership) => {
3441
+ if (this._isHidden(this._meshIdOf(mesh), mesh.workspaceKey))
3442
+ return;
3140
3443
  void this._recordMemberProof(mesh, membership);
3141
3444
  void this._followJoinedMeshes(mesh);
3142
3445
  if (mesh.role === 'workspace') {
@@ -3149,6 +3452,30 @@ export class Core extends ReadyResource {
3149
3452
  this._listenMesh(mesh, handlers);
3150
3453
  this._startMeshServices(entry);
3151
3454
  this._startEntryIndexing(entry);
3455
+ this._onMeshesDirty(entry, { changed: true, groupsChanged: true });
3456
+ this._reviewKick(mesh).catch((err) => this._log?.warn(['p2p', 'mesh'], 'reviewing a kick failed', err));
3457
+ }
3458
+ _onMeshesDirty(entry, { changed, groupsChanged }) {
3459
+ const { mesh } = entry;
3460
+ if (this._isHidden(this._meshIdOf(mesh), mesh.workspaceKey)) {
3461
+ return;
3462
+ }
3463
+ if (changed || entry.meshesPending) {
3464
+ void this._followJoinedMeshes(mesh);
3465
+ }
3466
+ if (changed && mesh.role === 'workspace') {
3467
+ void this._followProjects(mesh);
3468
+ void this._followHosting();
3469
+ }
3470
+ if (mesh.role === 'project') {
3471
+ void this._followUpgrade(mesh);
3472
+ }
3473
+ if ((changed || groupsChanged) && mesh.role === 'workspace') {
3474
+ this._followGroups(mesh);
3475
+ }
3476
+ if (this._isAccount(mesh) && (changed || entry.publicPending || !this._publicMesh())) {
3477
+ void this._followPublicMesh(mesh);
3478
+ }
3152
3479
  }
3153
3480
  _listenMesh(mesh, handlers) {
3154
3481
  mesh.autobee.on('writable', handlers.writable);
@@ -3179,13 +3506,16 @@ export class Core extends ReadyResource {
3179
3506
  this._candidateMesh = null;
3180
3507
  }
3181
3508
  await this.local.setAccountMesh(this._requireDeviceKeyPair().publicKey, mesh.key);
3509
+ for (const key of await this.local.unretire(mesh.key)) {
3510
+ this._retiredMeshes.delete(b4a.toHex(key));
3511
+ }
3182
3512
  this._wireMesh(this._poolEntry(mesh));
3183
3513
  this._accountId = this._meshIdOf(mesh);
3184
3514
  void this._deviceControl.revalidate();
3185
3515
  this._statusError = null;
3186
3516
  this._upgradeRequired = null;
3187
3517
  if (mesh.writable) {
3188
- this._kicked = false;
3518
+ void this.local.markAwaitingAdmission(mesh.key, { awaitingAdmission: false }).catch(noop);
3189
3519
  }
3190
3520
  this._notifyStatus();
3191
3521
  void this._followPublicMesh(mesh);
@@ -3311,8 +3641,16 @@ export class Core extends ReadyResource {
3311
3641
  return;
3312
3642
  }
3313
3643
  try {
3314
- if (!this.closing && this._isAccount(account)) {
3315
- await this._settlePublicMeshes(account);
3644
+ const current = this._accountMesh();
3645
+ for (let attempt = 1; !this.closing && current; attempt++) {
3646
+ const entry = this._meshes.get(this._meshIdOf(current));
3647
+ const settled = await this._settlePublicMeshes(current);
3648
+ if (entry) {
3649
+ entry.publicPending = !settled;
3650
+ }
3651
+ if (settled || attempt === PUBLIC_FOLLOW_ATTEMPTS) {
3652
+ break;
3653
+ }
3316
3654
  }
3317
3655
  }
3318
3656
  catch (err) {
@@ -3330,20 +3668,28 @@ export class Core extends ReadyResource {
3330
3668
  if (!ours) {
3331
3669
  return keys;
3332
3670
  }
3333
- for await (const joined of account.view.find(JOINED_MESHES)) {
3334
- const { meshKey } = joined;
3335
- const live = joined.workspace && !joined.leftAt && b4a.equals(joined.memberId, ours);
3336
- if (live && (await account.view.get(MESH_SEEDS, { meshKey }))) {
3337
- keys.push(meshKey);
3671
+ const snap = account.view.snapshot();
3672
+ try {
3673
+ for await (const joined of snap.find(JOINED_MESHES)) {
3674
+ const { meshKey } = joined;
3675
+ const live = joined.workspace && !joined.leftAt && b4a.equals(joined.memberId, ours);
3676
+ if (live && (await snap.get(MESH_SEEDS, { meshKey }))) {
3677
+ keys.push(meshKey);
3678
+ }
3338
3679
  }
3339
3680
  }
3681
+ finally {
3682
+ await snap.close();
3683
+ }
3340
3684
  return keys;
3341
3685
  }
3342
3686
  async _settlePublicMeshes(account) {
3687
+ let settled = true;
3343
3688
  try {
3344
3689
  await this._settleOwnWorkspace(account);
3345
3690
  }
3346
3691
  catch (err) {
3692
+ settled = false;
3347
3693
  if (!this.closing) {
3348
3694
  this._log?.warn(['p2p', 'mesh'], 'settling your own workspace failed', err);
3349
3695
  }
@@ -3351,17 +3697,19 @@ export class Core extends ReadyResource {
3351
3697
  const workspaces = await this._publicWorkspaces(account);
3352
3698
  for (const workspaceKey of workspaces) {
3353
3699
  if (this.closing || !this._isAccount(account))
3354
- return;
3700
+ return settled;
3355
3701
  try {
3356
3702
  await this._settlePublicMesh(account, workspaceKey);
3357
3703
  }
3358
3704
  catch (err) {
3705
+ settled = false;
3359
3706
  if (!this.closing) {
3360
3707
  this._log?.warn(['p2p', 'mesh'], 'following a public mesh failed', err);
3361
3708
  }
3362
3709
  }
3363
3710
  }
3364
3711
  await this._retireLeftPublic(account, workspaces);
3712
+ return settled;
3365
3713
  }
3366
3714
  async _settleOwnWorkspace(account) {
3367
3715
  const { own, lost } = await ownWorkspaces(account);
@@ -3371,6 +3719,9 @@ export class Core extends ReadyResource {
3371
3719
  }
3372
3720
  }
3373
3721
  const mints = account.minted || !(await bornUnderRules(account.view));
3722
+ if (!this._isAccount(account)) {
3723
+ return;
3724
+ }
3374
3725
  if (own || !mints) {
3375
3726
  this._setOwnWorkspace(own ? b4a.toHex(own) : null);
3376
3727
  return;
@@ -3379,8 +3730,12 @@ export class Core extends ReadyResource {
3379
3730
  }
3380
3731
  async _mintOwnWorkspace(account) {
3381
3732
  const seed = ownWorkspaceSeed(account.seed);
3382
- const recorded = (await this.local.listMeshes()).some((row) => b4a.equals(row.seed, seed));
3383
- if (recorded || !account.writable || !account.ourMemberId) {
3733
+ const recorded = (await this.local.listMeshes()).find((row) => b4a.equals(row.seed, seed));
3734
+ if (recorded) {
3735
+ await this._openPooledMesh(b4a.toHex(recorded.key), 'follow');
3736
+ return;
3737
+ }
3738
+ if (!account.writable || !account.ourMemberId) {
3384
3739
  return;
3385
3740
  }
3386
3741
  const workspace = { name: await this._defaultWorkspaceName(account) };
@@ -3588,11 +3943,17 @@ export class Core extends ReadyResource {
3588
3943
  _savePublicRecord(account, workspaceKey, record) {
3589
3944
  return this.local.set(publicRecordKey(account.key, workspaceKey), record);
3590
3945
  }
3946
+ _takePublicBoot(meshId) {
3947
+ const head = this._publicBoots.get(meshId) ?? null;
3948
+ this._publicBoots.delete(meshId);
3949
+ return head;
3950
+ }
3591
3951
  async _openPublicMesh(account, { workspaceKey, record, founder = null }) {
3592
3952
  const session = {
3593
3953
  seed: publicSeed(account.seed, workspaceKey),
3594
3954
  baseKey: record.key ? b4a.from(record.key, 'hex') : undefined,
3595
- writerSeed: record.writerSeed
3955
+ writerSeed: record.writerSeed,
3956
+ bootFrom: record.key ? this._takePublicBoot(record.key) : null
3596
3957
  };
3597
3958
  const mesh = this._newMesh(session, 'public');
3598
3959
  mesh.workspaceKey = workspaceKey;
@@ -3964,6 +4325,14 @@ export class Core extends ReadyResource {
3964
4325
  this._leftPublic.add(held);
3965
4326
  await this._announceDeparture(held);
3966
4327
  }
4328
+ }
4329
+ await this._rotatePublicWriters(account);
4330
+ }
4331
+ async _dropKickedCopy(meshId) {
4332
+ await this._teardownMesh(await this._openPooledMesh(meshId, 'leave'), { purge: true });
4333
+ }
4334
+ async _rotatePublicWriters(account) {
4335
+ for (const workspaceKey of await this._publicWorkspaces(account)) {
3967
4336
  const record = await this._publicRecord(account, workspaceKey);
3968
4337
  if (record) {
3969
4338
  await this.local.set(leftPublicRecordKey(account.key, workspaceKey), record);
@@ -3974,6 +4343,14 @@ export class Core extends ReadyResource {
3974
4343
  }
3975
4344
  }
3976
4345
  }
4346
+ async _restorePublicWriters(account) {
4347
+ for (const workspaceKey of await this._publicWorkspaces(account)) {
4348
+ const left = await this.local.get(leftPublicRecordKey(account.key, workspaceKey));
4349
+ if (isPublicRecord(left)) {
4350
+ await this._savePublicRecord(account, workspaceKey, left);
4351
+ }
4352
+ }
4353
+ }
3977
4354
  _pooled(meshKey) {
3978
4355
  if (meshKey === null)
3979
4356
  return null;
@@ -4007,7 +4384,9 @@ export class Core extends ReadyResource {
4007
4384
  vectorIndex: null,
4008
4385
  memberLock: new ScopeLock({ debounce: true }),
4009
4386
  followLock: new ScopeLock({ debounce: true }),
4010
- meshesPending: false
4387
+ kickLock: new ScopeLock({ debounce: true }),
4388
+ meshesPending: false,
4389
+ publicPending: false
4011
4390
  };
4012
4391
  this._meshes.set(key, entry);
4013
4392
  mesh.on('peer-add', () => this._onMeshPeer(mesh));
@@ -4085,9 +4464,15 @@ export class Core extends ReadyResource {
4085
4464
  if (await this.local.files.backfilled(mesh.key)) {
4086
4465
  return;
4087
4466
  }
4088
- await backfillFileIndex(mesh);
4467
+ const started = Date.now();
4468
+ const chunks = await backfillFileIndex(mesh);
4089
4469
  if (!mesh.closing) {
4090
4470
  await this.local.files.markBackfilled(mesh.key);
4471
+ this._log?.info(['files'], 'recorded the files the mesh already held', {
4472
+ mesh: b4a.toHex(mesh.key).slice(0, 8),
4473
+ chunks,
4474
+ ms: Date.now() - started
4475
+ });
4091
4476
  }
4092
4477
  }
4093
4478
  catch (err) {
@@ -4119,6 +4504,27 @@ export class Core extends ReadyResource {
4119
4504
  })
4120
4505
  .catch(failed);
4121
4506
  }
4507
+ async _backfillChatChunks(mesh) {
4508
+ if (!floorExcludesBefore(this._minSupportedVersion, REINDEX_FROM_APP_VERSION)) {
4509
+ return;
4510
+ }
4511
+ try {
4512
+ await mesh.waitForWritable();
4513
+ await mesh.autobee.update();
4514
+ const started = Date.now();
4515
+ const copied = await backfillChatChunks(mesh);
4516
+ this._log?.info(['p2p', 'mesh'], 'copied chats into chat-chunks', {
4517
+ mesh: b4a.toHex(mesh.key).slice(0, 8),
4518
+ copied,
4519
+ ms: Date.now() - started
4520
+ });
4521
+ }
4522
+ catch (err) {
4523
+ if (!mesh.closing) {
4524
+ this._log?.warn(['p2p', 'mesh'], 'copying chats into chat-chunks failed', err);
4525
+ }
4526
+ }
4527
+ }
4122
4528
  _servedFile(mesh, coreKey, blockOffset) {
4123
4529
  this.local.files
4124
4530
  .touch({ meshKey: mesh.key, coreKey, blockOffset })
@@ -4189,6 +4595,9 @@ export class Core extends ReadyResource {
4189
4595
  if (entry?.mesh === mesh) {
4190
4596
  this._unwireMesh(entry);
4191
4597
  this._meshes.delete(key);
4598
+ if (this._retiredMeshes.delete(key)) {
4599
+ this._notifyStatus();
4600
+ }
4192
4601
  wasAccount = this._accountId === key;
4193
4602
  }
4194
4603
  if (this._candidateMesh === mesh) {
@@ -4297,6 +4706,7 @@ export class Core extends ReadyResource {
4297
4706
  }
4298
4707
  };
4299
4708
  void this._indexMeshFiles(mesh).then(() => Promise.all([reclaim(), sweep()]));
4709
+ void this._backfillChatChunks(mesh);
4300
4710
  mesh.autobee.on('move-to', () => void sweep());
4301
4711
  }
4302
4712
  async _discardCandidateMesh() {
@@ -4355,68 +4765,85 @@ export class Core extends ReadyResource {
4355
4765
  }
4356
4766
  }
4357
4767
  }
4358
- async leaveMesh(meshId) {
4768
+ async leaveMesh(meshId, { workspace = false } = {}) {
4359
4769
  if (this.closing)
4360
4770
  return;
4361
4771
  if (!this.opened)
4362
4772
  await this.ready();
4363
4773
  if (this._leaving === meshId) {
4774
+ await this._leaveChecks;
4364
4775
  return;
4365
4776
  }
4366
4777
  if (this._leaving || this._minting) {
4367
4778
  throw new CoreError('MESH_TRANSITION_IN_PROGRESS');
4368
4779
  }
4369
- const departing = await this._openPooledMesh(meshId);
4780
+ this._leaving = meshId;
4781
+ const checks = this._checkLeave(meshId, workspace);
4782
+ this._leaveChecks = checks;
4783
+ try {
4784
+ const checked = await checks;
4785
+ if (checked.kicked) {
4786
+ await this._departKicked(checked.departing);
4787
+ }
4788
+ else {
4789
+ await this._leaveChecked(meshId, checked);
4790
+ }
4791
+ }
4792
+ finally {
4793
+ this._leaving = null;
4794
+ this._leaveChecks = null;
4795
+ this._notifyStatus();
4796
+ }
4797
+ }
4798
+ async _checkLeave(meshId, workspace) {
4799
+ const departing = await this._openPooledMesh(meshId, 'leave');
4800
+ if (workspace) {
4801
+ requireWorkspace(departing, meshId);
4802
+ }
4370
4803
  const account = this._accountMesh();
4371
4804
  if (account && isOwnWorkspace(account, departing)) {
4372
4805
  throw new CoreError('OWN_WORKSPACE_LEAVE_REFUSED');
4373
4806
  }
4374
- const member = departing.role === 'workspace' ? await this._leavingMember(departing) : null;
4807
+ const kicked = this._kickedMeshes.has(meshId) && departing !== account;
4808
+ const member = departing.role === 'workspace' && !kicked ? await this._leavingMember(departing) : null;
4375
4809
  const leavingAccount = await this._isStoredAccount(departing);
4810
+ return { departing, member, leavingAccount, kicked };
4811
+ }
4812
+ async _leaveChecked(meshId, { departing, member, leavingAccount }) {
4376
4813
  this._log?.info(['p2p', 'mesh'], 'leaving a mesh', {
4377
4814
  meshId: meshId.slice(0, 8),
4378
4815
  account: leavingAccount
4379
4816
  });
4380
- this._leaving = meshId;
4381
4817
  this._notifyStatus();
4382
- try {
4383
- if (leavingAccount) {
4384
- await this._departAllBut(departing);
4385
- if (this.closing) {
4386
- return;
4387
- }
4388
- }
4389
- if (leavingAccount) {
4390
- await this._leavePublicMesh(departing);
4391
- }
4392
- if (member) {
4393
- await this._leaveAsMember(departing, member);
4394
- }
4395
- await this._recordDeparture(departing);
4396
- await this._releaseJoinedMesh(departing.key);
4397
- if (!leavingAccount) {
4398
- await this._teardownMesh(departing);
4399
- this._departures?.flush();
4818
+ if (leavingAccount) {
4819
+ await this._departAllBut(departing);
4820
+ if (this.closing) {
4400
4821
  return;
4401
4822
  }
4402
- await this._archiveMembership(departing);
4403
- const landed = this._waitForMeshChange();
4404
- this._requestFreshMesh().catch(noop);
4405
- const error = await landed;
4406
- if (error) {
4407
- throw error;
4408
- }
4409
4823
  }
4410
- finally {
4411
- this._leaving = null;
4412
- this._notifyStatus();
4824
+ if (leavingAccount) {
4825
+ await this._leavePublicMesh(departing);
4826
+ }
4827
+ if (member) {
4828
+ await this._leaveAsMember(departing, member);
4829
+ }
4830
+ await this._recordDeparture(departing);
4831
+ await this._releaseJoinedMesh(departing.key);
4832
+ if (!leavingAccount) {
4833
+ await this._teardownMesh(departing);
4834
+ this._departures?.flush();
4835
+ return;
4836
+ }
4837
+ await this._archiveMembership(departing);
4838
+ const landed = this._waitForMeshChange();
4839
+ this._requestFreshMesh().catch(noop);
4840
+ const error = await landed;
4841
+ if (error) {
4842
+ throw error;
4413
4843
  }
4414
4844
  }
4415
- async leaveWorkspace(meshId) {
4416
- if (!this.opened)
4417
- await this.ready();
4418
- requireWorkspace(await this._openPooledMesh(meshId), meshId);
4419
- await this.leaveMesh(meshId);
4845
+ leaveWorkspace(meshId) {
4846
+ return this.leaveMesh(meshId, { workspace: true });
4420
4847
  }
4421
4848
  async _leavingMember(workspace) {
4422
4849
  const ours = workspace.ourMemberId ?? (await workspace.refreshOurMember())?.memberId;
@@ -4446,13 +4873,13 @@ export class Core extends ReadyResource {
4446
4873
  }
4447
4874
  await workspace.dispatch('remove-member', { memberId: ours, revokedAt: Date.now() });
4448
4875
  }
4449
- async _heldMesh(key) {
4876
+ async _heldMesh(key, reason = 'route') {
4450
4877
  const meshId = b4a.toHex(key);
4451
4878
  const held = this._pooled(meshId);
4452
4879
  if (held || !(await this.local.readMeshSession(key))) {
4453
4880
  return held;
4454
4881
  }
4455
- return this._openPooledMesh(meshId);
4882
+ return this._openPooledMesh(meshId, reason);
4456
4883
  }
4457
4884
  async _cascadeRemovals(workspace) {
4458
4885
  const ours = workspace.ourMemberId;
@@ -4509,8 +4936,11 @@ export class Core extends ReadyResource {
4509
4936
  if (this.closing || !ours || !own || own.revoked || !account?.writable) {
4510
4937
  return;
4511
4938
  }
4512
- const devices = await workspace.view.find(DEVICES).toArray();
4513
- const kicked = devices.filter((device) => device.revoked && ownedBy(device, ours) && (device.revokedAt ?? 0) > own.joinedAt);
4939
+ const devices = await devicesOfMember(workspace.view, ours);
4940
+ const kicked = devices.filter((device) => device.revoked &&
4941
+ !!device.revokedBy &&
4942
+ !(device.writerKey && b4a.equals(device.revokedBy, device.writerKey)) &&
4943
+ (device.revokedAt ?? 0) > own.joinedAt);
4514
4944
  for (const device of kicked) {
4515
4945
  const row = await account.view.get(DEVICES, { id: device.id });
4516
4946
  const writerKey = row && !row.revoked ? row.writerKey : null;
@@ -4564,8 +4994,9 @@ export class Core extends ReadyResource {
4564
4994
  const rows = await this.local.listMeshes();
4565
4995
  const registry = accountKey ? this._pooled(b4a.toHex(accountKey)) : null;
4566
4996
  const meshes = registry ? await this._ownMeshes(registry) : new Map();
4997
+ const shown = rows.filter((row) => !this._isHidden(b4a.toHex(row.key), row.workspaceKey));
4567
4998
  return {
4568
- meshes: await Promise.all(rows.map((row) => this._meshEntry(row, accountKey, meshes)))
4999
+ meshes: await Promise.all(shown.map((row) => this._meshEntry(row, accountKey, meshes)))
4569
5000
  };
4570
5001
  }
4571
5002
  async listArchivedMeshes() {
@@ -4653,7 +5084,7 @@ export class Core extends ReadyResource {
4653
5084
  return meshes;
4654
5085
  }
4655
5086
  for await (const joined of registry.view.find(JOINED_MESHES)) {
4656
- if (!joined.leftAt && b4a.equals(joined.memberId, ours)) {
5087
+ if (!joined.leftAt && !joined.kicked && b4a.equals(joined.memberId, ours)) {
4657
5088
  meshes.set(b4a.toHex(joined.meshKey), joined);
4658
5089
  }
4659
5090
  }
@@ -4741,10 +5172,7 @@ export class Core extends ReadyResource {
4741
5172
  }
4742
5173
  return `${member.name}'s Workspace`.slice(0, MAX_MESH_NAME_CHARS);
4743
5174
  }
4744
- async createMesh({ shared = false, compute = false } = {}) {
4745
- if (compute) {
4746
- throw new CoreError('COMPUTE_MESH_RETIRED');
4747
- }
5175
+ async createMesh({ shared = false } = {}) {
4748
5176
  if (!this.opened)
4749
5177
  await this.ready();
4750
5178
  await this._meshTransitionLock.lock();
@@ -4999,6 +5427,9 @@ export class Core extends ReadyResource {
4999
5427
  if (this._blockedByMinVersion()) {
5000
5428
  throw new CoreError('MESH_BELOW_FLOOR');
5001
5429
  }
5430
+ if (reason === 'leave') {
5431
+ await this._kickCloses.get(meshId);
5432
+ }
5002
5433
  const pooled = this._pooled(meshId);
5003
5434
  if (pooled && this._isForeign(pooled)) {
5004
5435
  throw new CoreError('MESH_NOT_FOUND', [meshId]);
@@ -5009,7 +5440,7 @@ export class Core extends ReadyResource {
5009
5440
  const retiring = this._retiring.get(meshId);
5010
5441
  if (retiring) {
5011
5442
  await retiring.catch(noop);
5012
- return this._openPooledMesh(meshId);
5443
+ return this._openPooledMesh(meshId, reason);
5013
5444
  }
5014
5445
  const inflight = this._opening.get(meshId);
5015
5446
  if (inflight) {
@@ -5030,7 +5461,7 @@ export class Core extends ReadyResource {
5030
5461
  const started = Date.now();
5031
5462
  const key = this._meshKeyOf(meshId);
5032
5463
  const session = await this.local.readMeshSession(key);
5033
- if (!session) {
5464
+ if (!session || (this._kickedMeshes.has(meshId) && reason !== 'leave')) {
5034
5465
  throw new CoreError('MESH_NOT_FOUND', [meshId]);
5035
5466
  }
5036
5467
  const stored = await this._storedAccountKey();
@@ -5046,6 +5477,10 @@ export class Core extends ReadyResource {
5046
5477
  void this._deviceControl.revalidate();
5047
5478
  void this._followPublicMesh(mesh);
5048
5479
  }
5480
+ for (const dirty of ['members-dirty', 'agents-dirty', 'skill-secrets-dirty', 'mesh-named']) {
5481
+ mesh.emit(dirty);
5482
+ }
5483
+ mesh.emit('meshes-dirty', true);
5049
5484
  if (this._isAccount(mesh) && this._statusError?.startsWith(MESH_DIED)) {
5050
5485
  this._statusError = null;
5051
5486
  }
@@ -5345,7 +5780,7 @@ export class Core extends ReadyResource {
5345
5780
  const workspace = mesh.role === 'workspace';
5346
5781
  if (opts.memberInvite) {
5347
5782
  if (!isOwnMesh) {
5348
- throw new CoreError('MEMBER_INVITE_ACCOUNT_REFUSED');
5783
+ throw new CoreError(mesh.writable ? 'MEMBER_INVITE_ACCOUNT_REFUSED' : 'MESH_STILL_JOINING');
5349
5784
  }
5350
5785
  if (isOwnWorkspace(registry, mesh)) {
5351
5786
  throw new CoreError('OWN_WORKSPACE_INVITE_REFUSED');
@@ -5366,9 +5801,7 @@ export class Core extends ReadyResource {
5366
5801
  throw new CoreError('DEVICE_INVITE_MESH_REFUSED');
5367
5802
  }
5368
5803
  }
5369
- const auto = mesh.autobee;
5370
- const info = await auto.system.getInfo();
5371
- const head = info && info.view.length > 0 ? await auto.trusted.mostRecentTrusted(auto.view, null) : null;
5804
+ const head = await inviteHead(mesh);
5372
5805
  const additionalNodes = this._swarm
5373
5806
  ? this._swarm.dht.toArray({ limit: INVITE_DHT_NODES_LIMIT })
5374
5807
  : [];
@@ -5390,7 +5823,7 @@ export class Core extends ReadyResource {
5390
5823
  return {
5391
5824
  baseKey: mesh.key,
5392
5825
  seed: mesh.seed,
5393
- fastForward: head ? { key: head.key, length: head.length } : null,
5826
+ fastForward: head,
5394
5827
  additionalNodes,
5395
5828
  blindPeers: blindPeerRows.length
5396
5829
  ? blindPeerRows.map((row) => row.key)
@@ -5401,9 +5834,25 @@ export class Core extends ReadyResource {
5401
5834
  deviceSeed: delegation?.deviceSeed,
5402
5835
  deviceProof: delegation?.deviceProof,
5403
5836
  workspace,
5404
- workspaceName: opts.memberInvite ? mesh.name?.name || undefined : undefined
5837
+ workspaceName: opts.memberInvite ? mesh.name?.name || undefined : undefined,
5838
+ publicHeads: opts.memberInvite ? [] : await this._publicHeads()
5405
5839
  };
5406
5840
  }
5841
+ async _publicHeads() {
5842
+ const heads = [];
5843
+ const ids = new Set([this._publicIdOf(this._accountId), ...this._publicIds.values()]);
5844
+ for (const meshId of ids) {
5845
+ const mesh = this._pooled(meshId);
5846
+ const head = mesh && (await inviteHead(mesh));
5847
+ if (head) {
5848
+ heads.push({ meshKey: mesh.key, head });
5849
+ }
5850
+ if (heads.length === INVITE_PUBLIC_HEADS_LIMIT) {
5851
+ break;
5852
+ }
5853
+ }
5854
+ return heads;
5855
+ }
5407
5856
  async _delegatePairing(account) {
5408
5857
  const keyPair = this._requireDeviceKeyPair();
5409
5858
  const own = await account.view.get(DEVICES, { id: keyPair.publicKey });
@@ -5501,7 +5950,18 @@ export class Core extends ReadyResource {
5501
5950
  this._skillSecrets.unlock();
5502
5951
  }
5503
5952
  }
5504
- async _followJoinedMeshes(memberMesh) {
5953
+ _followJoinedMeshes(memberMesh) {
5954
+ return this._followJoinedMeshesPass(memberMesh).catch((err) => {
5955
+ const entry = this._meshes.get(this._meshIdOf(memberMesh));
5956
+ if (entry?.mesh === memberMesh) {
5957
+ entry.meshesPending = true;
5958
+ }
5959
+ if (!this.closing) {
5960
+ this._log?.warn(['p2p', 'mesh'], 'following the joined meshes failed', err);
5961
+ }
5962
+ });
5963
+ }
5964
+ async _followJoinedMeshesPass(memberMesh) {
5505
5965
  if (this.closing || !this._isPooled(memberMesh))
5506
5966
  return;
5507
5967
  const entry = this._meshes.get(this._meshIdOf(memberMesh));
@@ -5566,6 +6026,10 @@ export class Core extends ReadyResource {
5566
6026
  if (await lostMint(memberMesh, joined.meshKey)) {
5567
6027
  return;
5568
6028
  }
6029
+ if (joined.kicked && !joined.leftAt) {
6030
+ await this._followKick(meshId, held);
6031
+ return;
6032
+ }
5569
6033
  if (joined.leftAt) {
5570
6034
  if (held) {
5571
6035
  tally.left++;
@@ -5580,6 +6044,13 @@ export class Core extends ReadyResource {
5580
6044
  tally.held++;
5581
6045
  return;
5582
6046
  }
6047
+ const joinedUnder = await this.local.joinedUnder(joined.meshKey);
6048
+ if (joinedUnder !== null && this._kickedMeshes.has(meshId)) {
6049
+ if (joined.joinedAt <= joinedUnder) {
6050
+ return;
6051
+ }
6052
+ await this._dropKickedCopy(meshId);
6053
+ }
5583
6054
  if (await this.local.readMeshSession(joined.meshKey)) {
5584
6055
  if (this._upgradeRequired !== 'halt' &&
5585
6056
  (await this.local.awaitsAdmission(joined.meshKey))) {
@@ -5666,12 +6137,25 @@ export class Core extends ReadyResource {
5666
6137
  deviceId: this._requireDeviceKeyPair().publicKey
5667
6138
  });
5668
6139
  await this.local.markAwaitingAdmission(meshKey, { awaitingAdmission: true });
6140
+ await this.local.markJoinedUnder(meshKey, joined.joinedAt);
6141
+ this._kickedMeshes.delete(b4a.toHex(meshKey));
5669
6142
  await this._openPooledMesh(b4a.toHex(meshKey), 'follow');
5670
6143
  return 'opened';
5671
6144
  }
5672
6145
  async _followProjects(workspace) {
5673
- const leaving = this._leaving === this._meshIdOf(workspace);
5674
- if (this.closing || leaving || this._upgradeRequired || this._blockedByMinVersion()) {
6146
+ try {
6147
+ await this._passProjects(workspace);
6148
+ }
6149
+ catch (err) {
6150
+ if (!this.closing) {
6151
+ this._log?.warn(['p2p', 'mesh'], 'following the projects failed', err);
6152
+ }
6153
+ }
6154
+ }
6155
+ async _passProjects(workspace) {
6156
+ if (!this._mayFollowProjects(workspace) ||
6157
+ this._upgradeRequired ||
6158
+ this._blockedByMinVersion()) {
5675
6159
  return;
5676
6160
  }
5677
6161
  if (!workspace.ourMemberId) {
@@ -5682,7 +6166,7 @@ export class Core extends ReadyResource {
5682
6166
  return;
5683
6167
  }
5684
6168
  for await (const project of workspace.view.find(PROJECTS)) {
5685
- if (this.closing || !this._isPooled(workspace)) {
6169
+ if (!this._mayFollowProjects(workspace)) {
5686
6170
  return;
5687
6171
  }
5688
6172
  const meshId = b4a.toHex(project.id);
@@ -5703,17 +6187,36 @@ export class Core extends ReadyResource {
5703
6187
  continue;
5704
6188
  }
5705
6189
  const held = this._pooled(meshId);
5706
- if (held && this._isForeign(held)) {
5707
- await this._releaseHostMesh(meshId, { replaced: true });
5708
- }
6190
+ const hosted = !!held && this._isForeign(held);
5709
6191
  const kicked = this._kickedProjects.get(meshId) === workspace;
5710
- if (kicked || this._following.has(meshId) || this._pooled(meshId)) {
6192
+ if (!hosted && !kicked && this._kickedMeshes.has(meshId)) {
6193
+ if (!this._following.has(meshId)) {
6194
+ await this._trackFollow(meshId, async () => {
6195
+ await this._dropKickedCopy(meshId);
6196
+ await this._openListedProject(workspace, project);
6197
+ });
6198
+ }
6199
+ continue;
6200
+ }
6201
+ if (this._following.has(meshId) || (!hosted && (held || kicked))) {
5711
6202
  continue;
5712
6203
  }
5713
- await this._trackFollow(meshId, () => this._openListedProject(workspace, project));
6204
+ await this._trackFollow(meshId, async () => {
6205
+ if (hosted) {
6206
+ await this._releaseHostMesh(meshId, { replaced: true });
6207
+ }
6208
+ if (!kicked) {
6209
+ await this._openListedProject(workspace, project);
6210
+ }
6211
+ });
5714
6212
  }
5715
6213
  void this._sealProjectKeys();
5716
6214
  }
6215
+ _mayFollowProjects(workspace) {
6216
+ const leaving = this._leaving !== null &&
6217
+ (this._leaving === this._accountId || this._leaving === this._meshIdOf(workspace));
6218
+ return !this.closing && !this._minting && !leaving && this._isPooled(workspace);
6219
+ }
5717
6220
  async _sealProjectKeys() {
5718
6221
  if (!(await this._projectKeySeals.lock()))
5719
6222
  return;
@@ -5806,6 +6309,9 @@ export class Core extends ReadyResource {
5806
6309
  return row && openSealedToDevice(row.sealedSeed, device);
5807
6310
  }
5808
6311
  async _projectGone(projectId) {
6312
+ if (this._isHidden(projectId, this._pooled(projectId)?.workspaceKey)) {
6313
+ return true;
6314
+ }
5809
6315
  return !(await this.local.readMeshSession(b4a.from(projectId, 'hex')));
5810
6316
  }
5811
6317
  async _isProjectOf(workspaceKey, key) {
@@ -5857,6 +6363,10 @@ export class Core extends ReadyResource {
5857
6363
  if (await this._departing(key)) {
5858
6364
  return;
5859
6365
  }
6366
+ const meshId = b4a.toHex(key);
6367
+ if (this._opening.has(meshId) || this._pooled(meshId)) {
6368
+ return;
6369
+ }
5860
6370
  const pending = await this.local.readPurge(key);
5861
6371
  if (pending) {
5862
6372
  await purgeCores(this.store, this.storage, pending.cores ?? []);
@@ -5897,7 +6407,7 @@ export class Core extends ReadyResource {
5897
6407
  return;
5898
6408
  }
5899
6409
  const seed = await this._ownProjectSeed(workspace, id);
5900
- if (!seed) {
6410
+ if (!seed || !this._mayFollowProjects(workspace)) {
5901
6411
  return;
5902
6412
  }
5903
6413
  const session = this.local.createCandidateSession(seed, id, {
@@ -6082,7 +6592,7 @@ export class Core extends ReadyResource {
6082
6592
  _meshPool() {
6083
6593
  return (meshId, request = {}) => {
6084
6594
  const pooled = this._pooled(meshId);
6085
- if (pooled && this._isForeign(pooled)) {
6595
+ if ((pooled && this._isForeign(pooled)) || this._isHidden(meshId, pooled?.workspaceKey)) {
6086
6596
  return null;
6087
6597
  }
6088
6598
  if (pooled && this._definesAgents(pooled, request)) {
@@ -6199,7 +6709,7 @@ export class Core extends ReadyResource {
6199
6709
  close: (meshId) => this.closeMesh(meshId),
6200
6710
  label: (meshId, label) => this.setMeshLabel(meshId, label),
6201
6711
  name: (meshId, name) => this.setMeshName(meshId, name),
6202
- createMesh: (opts) => this.createMesh(opts),
6712
+ createMesh: () => this.createMesh(),
6203
6713
  createWorkspace: (opts) => this.createWorkspace(opts),
6204
6714
  leaveWorkspace: (meshId) => this.leaveWorkspace(meshId),
6205
6715
  createProject: (workspaceId, opts) => this.createProject(workspaceId, opts),
@@ -6641,6 +7151,17 @@ export class Core extends ReadyResource {
6641
7151
  blindPeers: mesh.blindPeerStats()
6642
7152
  };
6643
7153
  }
7154
+ _meshProgress(mesh) {
7155
+ return {
7156
+ role: mesh.role,
7157
+ writable: mesh.writable,
7158
+ localLength: mesh.localLength,
7159
+ systemLength: mesh.autobee.system.bee.head()?.length ?? 0,
7160
+ viewLength: mesh.view.db.head()?.length ?? 0,
7161
+ fastForwards: mesh.autobee.stats.fastForwards,
7162
+ bootFrom: mesh.bootFrom
7163
+ };
7164
+ }
6644
7165
  _diagnostics() {
6645
7166
  const mesh = this._accountMesh();
6646
7167
  const publicMesh = this._publicMesh();
@@ -6662,6 +7183,7 @@ export class Core extends ReadyResource {
6662
7183
  state: this._statusState(),
6663
7184
  mesh: mesh ? this._meshDiagnostics(mesh) : null,
6664
7185
  publicMesh: publicMesh ? this._meshDiagnostics(publicMesh) : null,
7186
+ meshes: Object.fromEntries([...this._meshes].map(([id, { mesh }]) => [id, this._meshProgress(mesh)])),
6665
7187
  network: dht
6666
7188
  ? {
6667
7189
  online: dht.online ?? null,
@@ -6688,24 +7210,28 @@ export class Core extends ReadyResource {
6688
7210
  state: this._statusState(),
6689
7211
  peerCount: peerDeviceIds.length,
6690
7212
  peerDeviceIds,
6691
- kickedPending: this._kickedPending,
7213
+ kickedPending: this._kickNotice,
6692
7214
  error: this._statusError ?? undefined,
6693
7215
  blindPeersConnected: blindPeers.filter((peer) => peer.connected).length,
6694
7216
  blindPeersTotal: blindPeers.length
6695
7217
  };
6696
7218
  }
6697
7219
  acknowledgeKicked() {
6698
- if (!this._kickedPending)
7220
+ if (!this._kickNotice)
6699
7221
  return;
6700
- this._kickedPending = false;
7222
+ this._kickNotice = false;
6701
7223
  this._notifyStatus();
6702
7224
  }
7225
+ _accountKicked() {
7226
+ const account = this._accountMesh();
7227
+ return !!account && this._kickedMeshes.has(this._meshIdOf(account));
7228
+ }
6703
7229
  _statusState() {
6704
7230
  if (this._statusError)
6705
7231
  return 'error';
6706
7232
  if (this.closing || this._leaving)
6707
7233
  return 'leaving';
6708
- if (this._kicked) {
7234
+ if (this._accountKicked()) {
6709
7235
  return 'kicked';
6710
7236
  }
6711
7237
  if (this._upgradeRequired) {
@@ -6774,6 +7300,12 @@ async function closeConfigReader(reader) {
6774
7300
  await reader.core.close().catch(noop);
6775
7301
  await reader.close().catch(noop);
6776
7302
  }
7303
+ async function inviteHead(mesh) {
7304
+ const auto = mesh.autobee;
7305
+ const info = await auto.system.getInfo();
7306
+ const head = info && info.view.length > 0 ? await auto.trusted.mostRecentTrusted(auto.view, null) : null;
7307
+ return head ? { key: head.key, length: head.length } : null;
7308
+ }
6777
7309
  async function recordedBlockIsLocal(core) {
6778
7310
  await raceResource(core, core.ready(), 'config core');
6779
7311
  const length = Number((await raceResource(core, core.getUserData('hyperconf'), 'config core')) || '0');