@qvac/core 1.0.0-rc.7 → 1.0.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 (237) hide show
  1. package/CHANGELOG.md +241 -3
  2. package/README.md +1 -0
  3. package/dist-lib/lib/api/attachments.d.ts +1 -1
  4. package/dist-lib/lib/api/attachments.js +11 -0
  5. package/dist-lib/lib/api/chunks.d.ts +4 -2
  6. package/dist-lib/lib/api/chunks.js +6 -3
  7. package/dist-lib/lib/api/device-routes.d.ts +6 -1
  8. package/dist-lib/lib/api/device-routes.js +20 -1
  9. package/dist-lib/lib/api/devices.js +6 -18
  10. package/dist-lib/lib/api/execution.d.ts +6 -2
  11. package/dist-lib/lib/api/execution.js +29 -3
  12. package/dist-lib/lib/api/host-run-log.d.ts +7 -1
  13. package/dist-lib/lib/api/host-run-log.js +3 -1
  14. package/dist-lib/lib/api/index.d.ts +3 -1
  15. package/dist-lib/lib/api/index.js +17 -6
  16. package/dist-lib/lib/api/members.js +13 -29
  17. package/dist-lib/lib/api/mesh.d.ts +2 -1
  18. package/dist-lib/lib/api/projects.d.ts +1 -1
  19. package/dist-lib/lib/api/projects.js +9 -5
  20. package/dist-lib/lib/api/rag-label.d.ts +4 -0
  21. package/dist-lib/lib/api/rag-label.js +21 -0
  22. package/dist-lib/lib/api/rag-lexical.d.ts +22 -0
  23. package/dist-lib/lib/api/rag-lexical.js +1058 -0
  24. package/dist-lib/lib/api/rag-manifest.d.ts +13 -0
  25. package/dist-lib/lib/api/rag-manifest.js +46 -0
  26. package/dist-lib/lib/api/rag-outline.d.ts +36 -0
  27. package/dist-lib/lib/api/rag-outline.js +426 -0
  28. package/dist-lib/lib/api/rag-plugin.d.ts +20 -0
  29. package/dist-lib/lib/api/rag-plugin.js +70 -0
  30. package/dist-lib/lib/api/rag-synthesis.d.ts +7 -0
  31. package/dist-lib/lib/api/rag-synthesis.js +102 -0
  32. package/dist-lib/lib/api/rag-targets.d.ts +23 -0
  33. package/dist-lib/lib/api/rag-targets.js +215 -0
  34. package/dist-lib/lib/api/rag-window.d.ts +5 -0
  35. package/dist-lib/lib/api/rag-window.js +46 -0
  36. package/dist-lib/lib/api/rag.d.ts +3 -2
  37. package/dist-lib/lib/api/rag.js +421 -184
  38. package/dist-lib/lib/api/served.js +8 -14
  39. package/dist-lib/lib/api/workspace.d.ts +8 -1
  40. package/dist-lib/lib/api/workspace.js +27 -13
  41. package/dist-lib/lib/assistant/harness.d.ts +9 -1
  42. package/dist-lib/lib/assistant/history.d.ts +11 -2
  43. package/dist-lib/lib/assistant/history.js +74 -4
  44. package/dist-lib/lib/assistant/media-round.d.ts +61 -0
  45. package/dist-lib/lib/assistant/media-round.js +111 -0
  46. package/dist-lib/lib/assistant/message.d.ts +7 -0
  47. package/dist-lib/lib/assistant/model-round.d.ts +19 -1
  48. package/dist-lib/lib/assistant/model-round.js +163 -28
  49. package/dist-lib/lib/assistant/pdf-pages.d.ts +16 -1
  50. package/dist-lib/lib/assistant/pdf-pages.js +67 -3
  51. package/dist-lib/lib/assistant/round-host.d.ts +22 -0
  52. package/dist-lib/lib/assistant/round-host.js +142 -8
  53. package/dist-lib/lib/assistant/upload.d.ts +12 -0
  54. package/dist-lib/lib/assistant/upload.js +36 -0
  55. package/dist-lib/lib/assistant-client.d.ts +1 -0
  56. package/dist-lib/lib/assistant-client.js +40 -19
  57. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  58. package/dist-lib/lib/assistant-tree.js +48 -1
  59. package/dist-lib/lib/assistant.d.ts +18 -1
  60. package/dist-lib/lib/assistant.js +484 -95
  61. package/dist-lib/lib/client.d.ts +1 -0
  62. package/dist-lib/lib/client.js +4 -1
  63. package/dist-lib/lib/compaction.js +2 -2
  64. package/dist-lib/lib/core/agent.js +12 -45
  65. package/dist-lib/lib/core/approval-rules.js +1 -8
  66. package/dist-lib/lib/core/archived-mesh.d.ts +2 -1
  67. package/dist-lib/lib/core/archived-mesh.js +12 -8
  68. package/dist-lib/lib/core/chat-copy.d.ts +18 -3
  69. package/dist-lib/lib/core/chat-copy.js +74 -25
  70. package/dist-lib/lib/core/chat-fork.js +15 -6
  71. package/dist-lib/lib/core/chat-group.js +16 -24
  72. package/dist-lib/lib/core/chat-move.d.ts +9 -0
  73. package/dist-lib/lib/core/chat-move.js +94 -3
  74. package/dist-lib/lib/core/chat-order.js +12 -18
  75. package/dist-lib/lib/core/chat.js +38 -31
  76. package/dist-lib/lib/core/chunk.d.ts +2 -2
  77. package/dist-lib/lib/core/chunk.js +18 -25
  78. package/dist-lib/lib/core/collections.d.ts +2 -0
  79. package/dist-lib/lib/core/collections.js +2 -0
  80. package/dist-lib/lib/core/contract/activity.d.ts +4 -0
  81. package/dist-lib/lib/core/contract/activity.js +34 -4
  82. package/dist-lib/lib/core/contract/chat-group.d.ts +1 -0
  83. package/dist-lib/lib/core/contract/chat-group.js +21 -1
  84. package/dist-lib/lib/core/contract/chat.d.ts +9 -0
  85. package/dist-lib/lib/core/contract/chat.js +127 -5
  86. package/dist-lib/lib/core/contract/chunks.d.ts +1 -0
  87. package/dist-lib/lib/core/contract/chunks.js +37 -6
  88. package/dist-lib/lib/core/contract/features.d.ts +21 -0
  89. package/dist-lib/lib/core/contract/features.js +22 -0
  90. package/dist-lib/lib/core/contract/index.js +2 -0
  91. package/dist-lib/lib/core/contract/indexing.js +4 -2
  92. package/dist-lib/lib/core/contract/knowledge.js +5 -4
  93. package/dist-lib/lib/core/contract/members.js +16 -10
  94. package/dist-lib/lib/core/contract/mesh-kind.d.ts +1 -0
  95. package/dist-lib/lib/core/contract/mesh-kind.js +3 -1
  96. package/dist-lib/lib/core/contract/projects.d.ts +5 -0
  97. package/dist-lib/lib/core/contract/projects.js +13 -5
  98. package/dist-lib/lib/core/contract/roles.js +32 -4
  99. package/dist-lib/lib/core/contract/run-requests.d.ts +1 -0
  100. package/dist-lib/lib/core/contract/run-requests.js +35 -2
  101. package/dist-lib/lib/core/contract/seed-defaults.js +2 -2
  102. package/dist-lib/lib/core/contract/tool-configs.js +3 -2
  103. package/dist-lib/lib/core/contract/workspace.d.ts +2 -0
  104. package/dist-lib/lib/core/contract/workspace.js +40 -7
  105. package/dist-lib/lib/core/contract/writers.js +2 -2
  106. package/dist-lib/lib/core/departures.d.ts +3 -1
  107. package/dist-lib/lib/core/departures.js +3 -0
  108. package/dist-lib/lib/core/devices.js +1 -8
  109. package/dist-lib/lib/core/files/attachments.d.ts +2 -0
  110. package/dist-lib/lib/core/files/attachments.js +19 -1
  111. package/dist-lib/lib/core/files/index.d.ts +20 -4
  112. package/dist-lib/lib/core/files/index.js +132 -21
  113. package/dist-lib/lib/core/files/processing/document.d.ts +4 -0
  114. package/dist-lib/lib/core/files/processing/document.js +7 -0
  115. package/dist-lib/lib/core/files/processing/index.d.ts +13 -0
  116. package/dist-lib/lib/core/files/processing/index.js +144 -12
  117. package/dist-lib/lib/core/files/processing/protocol.js +13 -34
  118. package/dist-lib/lib/core/files/processing/state.d.ts +2 -0
  119. package/dist-lib/lib/core/files/rag/build.d.ts +19 -2
  120. package/dist-lib/lib/core/files/rag/build.js +123 -19
  121. package/dist-lib/lib/core/files/rag/failure.js +2 -1
  122. package/dist-lib/lib/core/files/rag/index.d.ts +11 -3
  123. package/dist-lib/lib/core/files/rag/index.js +13 -1
  124. package/dist-lib/lib/core/files/rag/load.d.ts +6 -3
  125. package/dist-lib/lib/core/files/rag/load.js +27 -6
  126. package/dist-lib/lib/core/files/rag/plugin-index.d.ts +32 -0
  127. package/dist-lib/lib/core/files/rag/plugin-index.js +127 -0
  128. package/dist-lib/lib/core/files/rag/produce.d.ts +5 -3
  129. package/dist-lib/lib/core/files/rag/produce.js +104 -16
  130. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +3 -1
  131. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +62 -13
  132. package/dist-lib/lib/core/files/rag/text-cache.d.ts +28 -0
  133. package/dist-lib/lib/core/files/rag/text-cache.js +141 -0
  134. package/dist-lib/lib/core/files/records/knowledge.d.ts +1 -3
  135. package/dist-lib/lib/core/files/records/knowledge.js +7 -40
  136. package/dist-lib/lib/core/files/records/reclaim.js +5 -10
  137. package/dist-lib/lib/core/files/upload.js +68 -41
  138. package/dist-lib/lib/core/fs-drives.js +14 -26
  139. package/dist-lib/lib/core/invite.d.ts +1 -0
  140. package/dist-lib/lib/core/invite.js +4 -2
  141. package/dist-lib/lib/core/local/files.d.ts +1 -1
  142. package/dist-lib/lib/core/local/files.js +5 -5
  143. package/dist-lib/lib/core/local/index.d.ts +13 -6
  144. package/dist-lib/lib/core/local/index.js +103 -69
  145. package/dist-lib/lib/core/local/run-logs.d.ts +1 -1
  146. package/dist-lib/lib/core/local/run-logs.js +5 -5
  147. package/dist-lib/lib/core/mesh-processor.d.ts +19 -0
  148. package/dist-lib/lib/core/mesh-processor.js +87 -0
  149. package/dist-lib/lib/core/mesh.d.ts +48 -5
  150. package/dist-lib/lib/core/mesh.js +318 -129
  151. package/dist-lib/lib/core/migrations/agent-catalog.js +2 -8
  152. package/dist-lib/lib/core/migrations/agent-tools-scope.js +5 -11
  153. package/dist-lib/lib/core/migrations/workspace-from-0-21/index.d.ts +88 -0
  154. package/dist-lib/lib/core/migrations/workspace-from-0-21/index.js +731 -0
  155. package/dist-lib/lib/core/migrations/writer-links.d.ts +2 -0
  156. package/dist-lib/lib/core/migrations/writer-links.js +32 -0
  157. package/dist-lib/lib/core/project-keys.d.ts +6 -0
  158. package/dist-lib/lib/core/project-keys.js +11 -0
  159. package/dist-lib/lib/core/public-mesh.d.ts +3 -0
  160. package/dist-lib/lib/core/public-mesh.js +10 -8
  161. package/dist-lib/lib/core/run-requests.d.ts +3 -0
  162. package/dist-lib/lib/core/run-requests.js +21 -1
  163. package/dist-lib/lib/core/skill-availability.d.ts +33 -0
  164. package/dist-lib/lib/core/skill-availability.js +67 -0
  165. package/dist-lib/lib/core/sync/background.d.ts +0 -1
  166. package/dist-lib/lib/core/sync/background.js +2 -1
  167. package/dist-lib/lib/core/sync/changed.d.ts +4 -2
  168. package/dist-lib/lib/core/sync/changed.js +1 -1
  169. package/dist-lib/lib/core/sync/index.js +52 -10
  170. package/dist-lib/lib/core/sync/view-updates.d.ts +18 -12
  171. package/dist-lib/lib/core/sync/view-updates.js +82 -91
  172. package/dist-lib/lib/core/sync-status.js +97 -41
  173. package/dist-lib/lib/core/tool-activity.js +6 -12
  174. package/dist-lib/lib/core/tool-configs.js +17 -29
  175. package/dist-lib/lib/core/upgrade-summary.d.ts +19 -0
  176. package/dist-lib/lib/core/upgrade-summary.js +67 -0
  177. package/dist-lib/lib/core/view-read.d.ts +4 -0
  178. package/dist-lib/lib/core/view-read.js +23 -0
  179. package/dist-lib/lib/core/workspace-upgrade.d.ts +7 -0
  180. package/dist-lib/lib/core/workspace-upgrade.js +27 -16
  181. package/dist-lib/lib/core.d.ts +45 -42
  182. package/dist-lib/lib/core.js +675 -640
  183. package/dist-lib/lib/errors.d.ts +24 -0
  184. package/dist-lib/lib/errors.js +24 -0
  185. package/dist-lib/lib/llm-model-names.d.ts +1 -1
  186. package/dist-lib/lib/llm-model-names.js +1 -1
  187. package/dist-lib/lib/mesh-scoped-engine.js +4 -0
  188. package/dist-lib/lib/model-context.js +1 -2
  189. package/dist-lib/lib/model-download.d.ts +6 -1
  190. package/dist-lib/lib/model-download.js +16 -3
  191. package/dist-lib/lib/oauth/resolve.js +29 -8
  192. package/dist-lib/lib/oauth/token-exchange-core.js +11 -0
  193. package/dist-lib/lib/probe-rounds.d.ts +7 -2
  194. package/dist-lib/lib/probe-rounds.js +6 -1
  195. package/dist-lib/lib/run-transcript.d.ts +4 -1
  196. package/dist-lib/lib/run-transcript.js +15 -6
  197. package/dist-lib/schema/engine.js +83 -6
  198. package/dist-lib/schema/indexes.d.ts +3 -0
  199. package/dist-lib/schema/indexes.js +5 -0
  200. package/dist-lib/schema/local.js +11 -2
  201. package/dist-lib/schema/qvac.js +49 -5
  202. package/dist-lib/spec/bind.js +34 -0
  203. package/dist-lib/spec/calls.js +5 -0
  204. package/dist-lib/spec/capabilities.d.ts +17 -0
  205. package/dist-lib/spec/hrpc/hrpc.json +65 -0
  206. package/dist-lib/spec/hrpc/index.js +68 -5
  207. package/dist-lib/spec/hrpc/messages.js +260 -23
  208. package/dist-lib/spec/hyperschema/index.js +260 -23
  209. package/dist-lib/spec/hyperschema/schema.json +181 -0
  210. package/dist-lib/spec/hyperschema/types.d.ts +48 -0
  211. package/dist-lib/spec/local/hyperdb/messages.js +270 -224
  212. package/dist-lib/spec/local/hyperschema/index.js +73 -38
  213. package/dist-lib/spec/local/hyperschema/schema.json +31 -0
  214. package/dist-lib/spec/local/hyperschema/types.d.ts +8 -0
  215. package/dist-lib/spec/mesh/hyperdb/db.json +39 -2
  216. package/dist-lib/spec/mesh/hyperdb/index.js +120 -3
  217. package/dist-lib/spec/mesh/hyperdb/messages.js +1328 -838
  218. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +30 -0
  219. package/dist-lib/spec/mesh/hyperdispatch/index.js +86 -1
  220. package/dist-lib/spec/mesh/hyperdispatch/messages.js +682 -287
  221. package/dist-lib/spec/mesh/hyperschema/index.js +682 -287
  222. package/dist-lib/spec/mesh/hyperschema/schema.json +201 -0
  223. package/dist-lib/spec/mesh/hyperschema/types.d.ts +52 -0
  224. package/package.json +82 -71
  225. package/tui/README.md +52 -0
  226. package/tui/app.mjs +69 -12
  227. package/tui/boot.mjs +27 -6
  228. package/tui/cli.mjs +93 -0
  229. package/tui/index.mjs +2 -87
  230. package/tui/lib/attachment-files.mjs +82 -0
  231. package/tui/lib/reopen-meshes.mjs +15 -0
  232. package/tui/lib/updater.mjs +86 -0
  233. package/tui/main.mjs +29 -57
  234. package/worker/assistant-sidecar.mjs +10 -3
  235. package/worker/stow-entry.mjs +3 -52
  236. package/dist-lib/lib/core/chat-project.d.ts +0 -2
  237. package/dist-lib/lib/core/chat-project.js +0 -15
@@ -51,7 +51,7 @@ export class LocalFiles {
51
51
  });
52
52
  }
53
53
  _write(files, next) {
54
- return this._locked(async () => {
54
+ return this._locked('_write', async () => {
55
55
  const tx = this._db.transaction();
56
56
  let changed = false;
57
57
  for (const file of files) {
@@ -72,7 +72,7 @@ export class LocalFiles {
72
72
  });
73
73
  }
74
74
  markCleared(file) {
75
- return this._locked(async () => {
75
+ return this._locked('markCleared', async () => {
76
76
  const tx = this._db.transaction();
77
77
  const known = await tx.get(LOCAL_FILES, keyOf(file));
78
78
  if (!known) {
@@ -84,7 +84,7 @@ export class LocalFiles {
84
84
  });
85
85
  }
86
86
  retireChats(meshKey, purged) {
87
- return this._locked(async () => {
87
+ return this._locked('retireChats', async () => {
88
88
  const tx = this._db.transaction();
89
89
  let changed = false;
90
90
  for (const row of await tx.find(LOCAL_FILES, meshRange(meshKey)).toArray()) {
@@ -104,7 +104,7 @@ export class LocalFiles {
104
104
  });
105
105
  }
106
106
  forget(file) {
107
- return this._locked(async () => {
107
+ return this._locked('forget', async () => {
108
108
  const tx = this._db.transaction();
109
109
  if (!(await tx.get(LOCAL_FILES, keyOf(file)))) {
110
110
  await tx.close();
@@ -123,7 +123,7 @@ export class LocalFiles {
123
123
  return ((await this._db.get(LOCAL_CONFIG, { key: backfillKey(meshKey) })) !== null);
124
124
  }
125
125
  markBackfilled(meshKey) {
126
- return this._locked(async () => {
126
+ return this._locked('markBackfilled', async () => {
127
127
  const tx = this._db.transaction();
128
128
  await tx.insert(LOCAL_CONFIG, { key: backfillKey(meshKey), value: true });
129
129
  await tx.flush();
@@ -1,5 +1,6 @@
1
1
  import CorestoreStorage from 'hypercore-storage';
2
2
  import HyperDB from 'hyperdb';
3
+ import type { LoggerInterface } from '@qvac/logging';
3
4
  import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatMove, LocalMeshUpdate, LocalMeshName, LocalChatNotify, LocalChatOrder, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalMeshPurge, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
4
5
  import type { QvacAutobeeHead } from '../../../spec/mesh/hyperschema/types.d.ts';
5
6
  import type { DeviceMetadata } from '../mesh.ts';
@@ -40,7 +41,7 @@ export declare const MESH_LOCAL_COLLECTIONS: readonly [{
40
41
  readonly collection: "@local/run-log-steps";
41
42
  readonly field: 'meshKey';
42
43
  }];
43
- export declare const MESH_CONFIG_FAMILIES: readonly ['workspace-upgrade', 'workspace-agents'];
44
+ export declare const MESH_CONFIG_FAMILIES: readonly ['workspace-upgrade', 'workspace-agents', 'workspace-edits', 'copied'];
44
45
  export interface ResolvedSession {
45
46
  readonly seed: Buffer;
46
47
  readonly baseKey: Buffer | undefined;
@@ -48,6 +49,7 @@ export interface ResolvedSession {
48
49
  readonly role?: MeshRole;
49
50
  readonly workspaceKey?: Buffer;
50
51
  readonly bootFrom?: QvacAutobeeHead | null;
52
+ readonly joinHeads?: ReadonlyArray<QvacAutobeeHead>;
51
53
  }
52
54
  export interface ArchivedMeshMembership extends LocalMeshMembership {
53
55
  readonly leftAt: number;
@@ -114,6 +116,9 @@ export interface DropMeshOptions {
114
116
  export interface RecordDepartureOptions {
115
117
  readonly creator: boolean;
116
118
  }
119
+ interface ArchiveMeshOptions {
120
+ readonly homeTo?: Buffer | null;
121
+ }
117
122
  export interface AdoptAccountMeshOptions {
118
123
  readonly account?: Buffer | null;
119
124
  readonly keepName?: boolean;
@@ -122,13 +127,14 @@ export interface MarkAwaitingAdmissionOptions {
122
127
  readonly awaitingAdmission: boolean;
123
128
  }
124
129
  export declare function recordedRole(row: Pick<LocalMeshMembership, 'role' | 'wasHome'>): MeshRole;
125
- export declare function openLocalStore(storage: CorestoreStorage): LocalStore;
130
+ export declare function openLocalStore(storage: CorestoreStorage, log?: LoggerInterface | null): LocalStore;
126
131
  declare class LocalStore {
127
132
  private readonly _db;
128
133
  private readonly _writeLock;
134
+ private readonly _log;
129
135
  readonly files: LocalFiles;
130
136
  readonly runLogs: LocalRunLogs;
131
- constructor(db: HyperDB);
137
+ constructor(db: HyperDB, log: LoggerInterface | null);
132
138
  private _locked;
133
139
  get(key: string): Promise<unknown>;
134
140
  set(key: string, value: unknown): Promise<void>;
@@ -167,9 +173,9 @@ declare class LocalStore {
167
173
  readAccountRecovery(meshKey: Buffer): Promise<LocalAccountRecovery | null>;
168
174
  readChatMove(meshKey: Buffer, chatId: string): Promise<LocalChatMove | null>;
169
175
  listChatMoves(): Promise<LocalChatMove[]>;
176
+ listChatMovesFrom(meshKey: Buffer): Promise<LocalChatMove[]>;
170
177
  readMeshUpdate(meshKey: Buffer): Promise<LocalMeshUpdate | null>;
171
- writeMeshUpdate(row: LocalMeshUpdate): Promise<void>;
172
- clearMeshUpdate(meshKey: Buffer): Promise<void>;
178
+ updateMeshUpdate(meshKey: Buffer, change: (row: LocalMeshUpdate | null) => LocalMeshUpdate | null): Promise<void>;
173
179
  meshNames(): Promise<LocalMeshName[]>;
174
180
  keepMeshName(row: LocalMeshName): Promise<void>;
175
181
  recordChatMove(row: LocalChatMove): Promise<void>;
@@ -189,7 +195,7 @@ declare class LocalStore {
189
195
  departures(): Promise<LocalMeshDeparture[]>;
190
196
  departureRole(departure: LocalMeshDeparture): Promise<MeshRole>;
191
197
  deleteDeparture(key: Buffer): Promise<void>;
192
- archiveMesh(key: Buffer): Promise<void>;
198
+ archiveMesh(key: Buffer, { homeTo }?: ArchiveMeshOptions): Promise<void>;
193
199
  markRetired(keys: Buffer[], accountKey: Buffer): Promise<void>;
194
200
  unretire(accountKey: Buffer): Promise<Buffer[]>;
195
201
  markKicked(key: Buffer): Promise<void>;
@@ -203,6 +209,7 @@ declare class LocalStore {
203
209
  private _dropMeshConfig;
204
210
  private _dropRows;
205
211
  markAwaitingAdmission(key: Buffer, opts: MarkAwaitingAdmissionOptions): Promise<void>;
212
+ recordJoinHeads(key: Buffer, joinHeads: ReadonlyArray<QvacAutobeeHead>): Promise<void>;
206
213
  markJoinedUnder(key: Buffer, joinedAt: number): Promise<void>;
207
214
  joinedUnder(key: Buffer): Promise<number | null>;
208
215
  setMeshRole(key: Buffer, role: MeshRole): Promise<void>;
@@ -24,10 +24,16 @@ export const MESH_LOCAL_COLLECTIONS = [
24
24
  { collection: LOCAL_RUN_LOGS, field: 'meshKey' },
25
25
  { collection: LOCAL_RUN_LOG_STEPS, field: 'meshKey' }
26
26
  ];
27
- export const MESH_CONFIG_FAMILIES = ['workspace-upgrade', 'workspace-agents'];
27
+ export const MESH_CONFIG_FAMILIES = [
28
+ 'workspace-upgrade',
29
+ 'workspace-agents',
30
+ 'workspace-edits',
31
+ 'copied'
32
+ ];
28
33
  const IDENTITY_ID = 'identity';
29
34
  const MEMBERSHIP_ID = 'membership';
30
35
  const APP_CONFIG_ID = 'default';
36
+ const SLOW_LOCK_MS = 1000;
31
37
  function freshWriterSeed() {
32
38
  return `local-${b4a.toHex(crypto.randomBytes(8))}`;
33
39
  }
@@ -38,7 +44,8 @@ function sessionOf(row) {
38
44
  writerSeed: row.writerSeed ?? undefined,
39
45
  role: meshRole(row.role),
40
46
  workspaceKey: row.workspaceKey ?? undefined,
41
- bootFrom: row.bootKey ? { key: row.bootKey, length: row.bootLength ?? 0 } : null
47
+ bootFrom: row.bootKey ? { key: row.bootKey, length: row.bootLength ?? 0 } : null,
48
+ joinHeads: row.joinHeads ?? []
42
49
  };
43
50
  }
44
51
  function meshRole(role) {
@@ -47,27 +54,36 @@ function meshRole(role) {
47
54
  export function recordedRole(row) {
48
55
  return meshRole(row.role) ?? (row.wasHome ? 'account' : 'project');
49
56
  }
50
- export function openLocalStore(storage) {
57
+ export function openLocalStore(storage, log = null) {
51
58
  const db = HyperDB.rocks(storage.rocks.columnFamily('assistant/local'), LocalDatabaseSpec);
52
- return new LocalStore(db);
59
+ return new LocalStore(db, log);
53
60
  }
54
61
  class LocalStore {
55
62
  _db;
56
63
  _writeLock = new ScopeLock();
64
+ _log;
57
65
  files;
58
66
  runLogs;
59
- constructor(db) {
67
+ constructor(db, log) {
60
68
  this._db = db;
61
- this.files = new LocalFiles(db, (fn) => this._locked(fn));
62
- this.runLogs = new LocalRunLogs(db, (fn) => this._locked(fn));
69
+ this._log = log;
70
+ this.files = new LocalFiles(db, (op, fn) => this._locked(`files.${op}`, fn));
71
+ this.runLogs = new LocalRunLogs(db, (op, fn) => this._locked(`runLogs.${op}`, fn));
63
72
  }
64
- async _locked(fn) {
73
+ async _locked(op, fn) {
74
+ const asked = Date.now();
65
75
  await this._writeLock.lock();
76
+ const took = Date.now();
66
77
  try {
67
78
  return await fn();
68
79
  }
69
80
  finally {
70
81
  this._writeLock.unlock();
82
+ const waited = took - asked;
83
+ const held = Date.now() - took;
84
+ if (waited > SLOW_LOCK_MS || held > SLOW_LOCK_MS) {
85
+ this._log?.warn('core', 'local store lock slow', { op, waited, held });
86
+ }
71
87
  }
72
88
  }
73
89
  async get(key) {
@@ -75,14 +91,14 @@ class LocalStore {
75
91
  return row === null ? null : readConfigValue(row);
76
92
  }
77
93
  set(key, value) {
78
- return this._locked(async () => {
94
+ return this._locked('set', async () => {
79
95
  const tx = this._db.transaction();
80
96
  await tx.insert(LOCAL_CONFIG, { key, ...configValue(value) });
81
97
  await tx.flush();
82
98
  });
83
99
  }
84
100
  setAll(entries) {
85
- return this._locked(async () => {
101
+ return this._locked('setAll', async () => {
86
102
  const tx = this._db.transaction();
87
103
  for (const { key, value } of entries) {
88
104
  await tx.insert(LOCAL_CONFIG, { key, ...configValue(value) });
@@ -91,7 +107,7 @@ class LocalStore {
91
107
  });
92
108
  }
93
109
  rekey(fromKey, toKey) {
94
- return this._locked(async () => {
110
+ return this._locked('rekey', async () => {
95
111
  const row = await this._db.get(LOCAL_CONFIG, { key: fromKey });
96
112
  if (!row) {
97
113
  return null;
@@ -104,7 +120,7 @@ class LocalStore {
104
120
  });
105
121
  }
106
122
  deleteAll(keys) {
107
- return this._locked(async () => {
123
+ return this._locked('deleteAll', async () => {
108
124
  const tx = this._db.transaction();
109
125
  for (const key of keys) {
110
126
  await tx.delete(LOCAL_CONFIG, { key });
@@ -113,7 +129,7 @@ class LocalStore {
113
129
  });
114
130
  }
115
131
  change(plan) {
116
- return this._locked(async () => {
132
+ return this._locked('change', async () => {
117
133
  const { result, set, delete: drop } = await plan((key) => this.get(key));
118
134
  const tx = this._db.transaction();
119
135
  for (const { key, value } of set) {
@@ -127,7 +143,7 @@ class LocalStore {
127
143
  });
128
144
  }
129
145
  deletePrefix(prefix) {
130
- return this._locked(async () => {
146
+ return this._locked('deletePrefix', async () => {
131
147
  const tx = this._db.transaction();
132
148
  const range = { gte: { key: prefix }, lt: { key: `${prefix}\uffff` } };
133
149
  for await (const row of this._db.find(LOCAL_CONFIG, range)) {
@@ -145,7 +161,7 @@ class LocalStore {
145
161
  return this._db.get(LOCAL_APP_CONFIG, { id: APP_CONFIG_ID });
146
162
  }
147
163
  updateAppConfigRow(mutate) {
148
- return this._locked(async () => {
164
+ return this._locked('updateAppConfigRow', async () => {
149
165
  const tx = this._db.transaction();
150
166
  const current = await tx.get(LOCAL_APP_CONFIG, { id: APP_CONFIG_ID });
151
167
  const next = { id: APP_CONFIG_ID, ...mutate(current) };
@@ -155,10 +171,10 @@ class LocalStore {
155
171
  });
156
172
  }
157
173
  getChatNotify(chatId) {
158
- return this._locked(() => this._db.get(LOCAL_CHAT_NOTIFY, { chatId }));
174
+ return this._locked('getChatNotify', () => this._db.get(LOCAL_CHAT_NOTIFY, { chatId }));
159
175
  }
160
176
  ackChatNotify(chatId, seq) {
161
- return this._locked(async () => {
177
+ return this._locked('ackChatNotify', async () => {
162
178
  const tx = this._db.transaction();
163
179
  const current = await tx.get(LOCAL_CHAT_NOTIFY, { chatId });
164
180
  const ackedThrough = Math.max(current?.ackedThrough ?? 0, seq + 1);
@@ -167,14 +183,14 @@ class LocalStore {
167
183
  });
168
184
  }
169
185
  clearChatNotify(chatId) {
170
- return this._locked(async () => {
186
+ return this._locked('clearChatNotify', async () => {
171
187
  const tx = this._db.transaction();
172
188
  await tx.delete(LOCAL_CHAT_NOTIFY, { chatId });
173
189
  await tx.flush();
174
190
  });
175
191
  }
176
192
  writeChatOrder(meshKey, rows, gone = []) {
177
- return this._locked(async () => {
193
+ return this._locked('writeChatOrder', async () => {
178
194
  const tx = this._db.transaction();
179
195
  for (const row of rows) {
180
196
  await tx.insert(LOCAL_CHAT_ORDER, { meshKey, ...row });
@@ -210,7 +226,7 @@ class LocalStore {
210
226
  .toArray();
211
227
  }
212
228
  beginModelTransfer(name, { transferred = false } = {}) {
213
- return this._locked(async () => {
229
+ return this._locked('beginModelTransfer', async () => {
214
230
  const current = await this._db.get(LOCAL_MODEL_NOTIFY, { name });
215
231
  const pending = current && current.transferId !== current.notificationId;
216
232
  if (pending && (!transferred || current.transferred)) {
@@ -231,7 +247,7 @@ class LocalStore {
231
247
  });
232
248
  }
233
249
  completeModelTransfer({ name, transferId, downloaded = true }) {
234
- return this._locked(async () => {
250
+ return this._locked('completeModelTransfer', async () => {
235
251
  const current = await this._db.get(LOCAL_MODEL_NOTIFY, { name });
236
252
  if (!current || current.transferId !== transferId || current.notificationId === transferId) {
237
253
  return;
@@ -252,10 +268,10 @@ class LocalStore {
252
268
  });
253
269
  }
254
270
  getModelNotifications() {
255
- return this._locked(() => this._db.find(LOCAL_MODEL_NOTIFY).toArray());
271
+ return this._locked('getModelNotifications', () => this._db.find(LOCAL_MODEL_NOTIFY).toArray());
256
272
  }
257
273
  ackModelNotification(notificationId) {
258
- return this._locked(async () => {
274
+ return this._locked('ackModelNotification', async () => {
259
275
  const rows = await this._db.find(LOCAL_MODEL_NOTIFY).toArray();
260
276
  const current = rows.find((row) => row.notificationId === notificationId);
261
277
  if (!current || current.acknowledged) {
@@ -281,14 +297,14 @@ class LocalStore {
281
297
  return rows;
282
298
  }
283
299
  putModelDownloadRow(row) {
284
- return this._locked(async () => {
300
+ return this._locked('putModelDownloadRow', async () => {
285
301
  const tx = this._db.transaction();
286
302
  await tx.insert(LOCAL_MODEL_DOWNLOAD, row);
287
303
  await tx.flush();
288
304
  });
289
305
  }
290
306
  deleteModelDownloadRow(name) {
291
- return this._locked(async () => {
307
+ return this._locked('deleteModelDownloadRow', async () => {
292
308
  const tx = this._db.transaction();
293
309
  await tx.delete(LOCAL_MODEL_DOWNLOAD, { name });
294
310
  await tx.flush();
@@ -302,7 +318,7 @@ class LocalStore {
302
318
  return rows;
303
319
  }
304
320
  putCustomModelRowIfLabelAvailable(row) {
305
- return this._locked(async () => {
321
+ return this._locked('putCustomModelRowIfLabelAvailable', async () => {
306
322
  const rows = [];
307
323
  for await (const current of this._db.find(LOCAL_CUSTOM_MODEL)) {
308
324
  rows.push(current);
@@ -318,14 +334,14 @@ class LocalStore {
318
334
  });
319
335
  }
320
336
  deleteCustomModelRow(name) {
321
- return this._locked(async () => {
337
+ return this._locked('deleteCustomModelRow', async () => {
322
338
  const tx = this._db.transaction();
323
339
  await tx.delete(LOCAL_CUSTOM_MODEL, { name });
324
340
  await tx.flush();
325
341
  });
326
342
  }
327
343
  ensureDevice(publicKey, seed) {
328
- return this._locked(async () => {
344
+ return this._locked('ensureDevice', async () => {
329
345
  const existing = await this._db.get(LOCAL_DEVICE, { publicKey });
330
346
  if (existing) {
331
347
  return {
@@ -350,7 +366,7 @@ class LocalStore {
350
366
  });
351
367
  }
352
368
  renameDevice(publicKey, name) {
353
- return this._locked(async () => {
369
+ return this._locked('renameDevice', async () => {
354
370
  const existing = await this._db.get(LOCAL_DEVICE, { publicKey });
355
371
  if (!existing) {
356
372
  return;
@@ -361,7 +377,7 @@ class LocalStore {
361
377
  });
362
378
  }
363
379
  saveDeviceProfile(publicKey, { capabilityProfile, recommendedModelName, platform }) {
364
- return this._locked(async () => {
380
+ return this._locked('saveDeviceProfile', async () => {
365
381
  const existing = await this._db.get(LOCAL_DEVICE, { publicKey });
366
382
  if (!existing) {
367
383
  return;
@@ -380,7 +396,7 @@ class LocalStore {
380
396
  return this._db.get(LOCAL_IDENTITY, { id: IDENTITY_ID });
381
397
  }
382
398
  saveDisplayName(displayName, displayNameAt = Date.now()) {
383
- return this._locked(async () => {
399
+ return this._locked('saveDisplayName', async () => {
384
400
  const tx = this._db.transaction();
385
401
  const existing = await tx.get(LOCAL_IDENTITY, { id: IDENTITY_ID });
386
402
  if (!existing) {
@@ -397,7 +413,7 @@ class LocalStore {
397
413
  return this._db.get(LOCAL_MEMBER_PROOF, { meshKey });
398
414
  }
399
415
  recordMemberProof(link) {
400
- return this._locked(async () => {
416
+ return this._locked('recordMemberProof', async () => {
401
417
  const existing = await this._db.get(LOCAL_MEMBER_PROOF, {
402
418
  meshKey: link.meshKey
403
419
  });
@@ -418,20 +434,23 @@ class LocalStore {
418
434
  listChatMoves() {
419
435
  return this._db.find(LOCAL_CHAT_MOVES).toArray();
420
436
  }
437
+ listChatMovesFrom(meshKey) {
438
+ const range = { gte: { meshKey }, lte: { meshKey } };
439
+ return this._db.find(LOCAL_CHAT_MOVES, range).toArray();
440
+ }
421
441
  readMeshUpdate(meshKey) {
422
442
  return this._db.get(LOCAL_MESH_UPDATES, { meshKey });
423
443
  }
424
- writeMeshUpdate(row) {
425
- return this._locked(async () => {
426
- const tx = this._db.transaction();
427
- await tx.insert(LOCAL_MESH_UPDATES, row);
428
- await tx.flush();
429
- });
430
- }
431
- clearMeshUpdate(meshKey) {
432
- return this._locked(async () => {
444
+ updateMeshUpdate(meshKey, change) {
445
+ return this._locked('updateMeshUpdate', async () => {
433
446
  const tx = this._db.transaction();
434
- await tx.delete(LOCAL_MESH_UPDATES, { meshKey });
447
+ const row = change(await tx.get(LOCAL_MESH_UPDATES, { meshKey }));
448
+ if (row) {
449
+ await tx.insert(LOCAL_MESH_UPDATES, row);
450
+ }
451
+ else {
452
+ await tx.delete(LOCAL_MESH_UPDATES, { meshKey });
453
+ }
435
454
  await tx.flush();
436
455
  });
437
456
  }
@@ -439,35 +458,35 @@ class LocalStore {
439
458
  return this._db.find(LOCAL_MESH_NAMES).toArray();
440
459
  }
441
460
  keepMeshName(row) {
442
- return this._locked(async () => {
461
+ return this._locked('keepMeshName', async () => {
443
462
  const tx = this._db.transaction();
444
463
  await tx.insert(LOCAL_MESH_NAMES, row);
445
464
  await tx.flush();
446
465
  });
447
466
  }
448
467
  recordChatMove(row) {
449
- return this._locked(async () => {
468
+ return this._locked('recordChatMove', async () => {
450
469
  const tx = this._db.transaction();
451
470
  await tx.insert(LOCAL_CHAT_MOVES, row);
452
471
  await tx.flush();
453
472
  });
454
473
  }
455
474
  dropChatMove({ meshKey, chatId }) {
456
- return this._locked(async () => {
475
+ return this._locked('dropChatMove', async () => {
457
476
  const tx = this._db.transaction();
458
477
  await tx.delete(LOCAL_CHAT_MOVES, { meshKey, chatId });
459
478
  await tx.flush();
460
479
  });
461
480
  }
462
481
  recordAccountRecovery(row) {
463
- return this._locked(async () => {
482
+ return this._locked('recordAccountRecovery', async () => {
464
483
  const tx = this._db.transaction();
465
484
  await tx.insert(LOCAL_ACCOUNT_RECOVERY, row);
466
485
  await tx.flush();
467
486
  });
468
487
  }
469
488
  replaceIdentity(identity) {
470
- return this._locked(async () => {
489
+ return this._locked('replaceIdentity', async () => {
471
490
  const tx = this._db.transaction();
472
491
  const existing = await tx.get(LOCAL_IDENTITY, { id: IDENTITY_ID });
473
492
  await tx.insert(LOCAL_IDENTITY, {
@@ -480,7 +499,7 @@ class LocalStore {
480
499
  });
481
500
  }
482
501
  ensureIdentity(devicePublicKey, createdAt) {
483
- return this._locked(async () => {
502
+ return this._locked('ensureIdentity', async () => {
484
503
  const existing = await this._db.get(LOCAL_IDENTITY, { id: IDENTITY_ID });
485
504
  if (existing) {
486
505
  return { identity: existing, mnemonic: null };
@@ -547,7 +566,7 @@ class LocalStore {
547
566
  return row && !row.leftAt ? row : null;
548
567
  }
549
568
  _migrateLegacySession(deviceId) {
550
- return this._locked(async () => {
569
+ return this._locked('_migrateLegacySession', async () => {
551
570
  const legacy = await this._legacyMembership(deviceId);
552
571
  if (!legacy) {
553
572
  return null;
@@ -585,7 +604,7 @@ class LocalStore {
585
604
  return { key: session.meshKey ?? null, seed: session.meshSeed, writerSeed: null };
586
605
  }
587
606
  recordMesh(key, session, { deviceId, account = false, initial }) {
588
- return this._locked(async () => {
607
+ return this._locked('recordMesh', async () => {
589
608
  const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
590
609
  const minted = account && !existing && session.baseKey === undefined;
591
610
  const tx = this._db.transaction();
@@ -600,7 +619,8 @@ class LocalStore {
600
619
  role: session.role ?? existing?.role,
601
620
  workspaceKey: session.workspaceKey ?? existing?.workspaceKey,
602
621
  joinedAt: existing?.joinedAt,
603
- initial: initial || existing?.initial
622
+ initial: initial || existing?.initial,
623
+ joinHeads: session.joinHeads ? [...session.joinHeads] : null
604
624
  });
605
625
  if (minted) {
606
626
  await tx.insert(LOCAL_ACTIVE_MESH, { deviceId, homeMeshKey: key });
@@ -609,14 +629,14 @@ class LocalStore {
609
629
  });
610
630
  }
611
631
  setAccountMesh(deviceId, key) {
612
- return this._locked(async () => {
632
+ return this._locked('setAccountMesh', async () => {
613
633
  const tx = this._db.transaction();
614
634
  await tx.insert(LOCAL_ACTIVE_MESH, { deviceId, homeMeshKey: key });
615
635
  await tx.flush();
616
636
  });
617
637
  }
618
638
  recordDeparture(key, opts) {
619
- return this._locked(async () => {
639
+ return this._locked('recordDeparture', async () => {
620
640
  const tx = this._db.transaction();
621
641
  const row = await tx.get(LOCAL_MESH_MEMBERSHIP, { key });
622
642
  if (!row) {
@@ -648,14 +668,14 @@ class LocalStore {
648
668
  return meshRole(departure.role) ?? recordedRole({ role: row?.role, wasHome: row?.wasHome });
649
669
  }
650
670
  deleteDeparture(key) {
651
- return this._locked(async () => {
671
+ return this._locked('deleteDeparture', async () => {
652
672
  const tx = this._db.transaction();
653
673
  await tx.delete(LOCAL_MESH_DEPARTURE, { key });
654
674
  await tx.flush();
655
675
  });
656
676
  }
657
- archiveMesh(key) {
658
- return this._locked(async () => {
677
+ archiveMesh(key, { homeTo = null } = {}) {
678
+ return this._locked('archiveMesh', async () => {
659
679
  const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
660
680
  const { cleared, home } = await this._pointersAt(key);
661
681
  const tx = this._db.transaction();
@@ -667,7 +687,7 @@ class LocalStore {
667
687
  });
668
688
  }
669
689
  for (const pointer of cleared) {
670
- await tx.insert(LOCAL_ACTIVE_MESH, pointer);
690
+ await tx.insert(LOCAL_ACTIVE_MESH, { ...pointer, homeMeshKey: homeTo });
671
691
  }
672
692
  await this._dropChatOrder(tx, key);
673
693
  await this._dropRows(tx, key, { collection: LOCAL_FILES, field: 'meshKey' });
@@ -677,7 +697,7 @@ class LocalStore {
677
697
  });
678
698
  }
679
699
  markRetired(keys, accountKey) {
680
- return this._locked(async () => {
700
+ return this._locked('markRetired', async () => {
681
701
  const tx = this._db.transaction();
682
702
  for (const key of keys) {
683
703
  const existing = await tx.get(LOCAL_MESH_MEMBERSHIP, { key });
@@ -692,7 +712,7 @@ class LocalStore {
692
712
  });
693
713
  }
694
714
  unretire(accountKey) {
695
- return this._locked(async () => {
715
+ return this._locked('unretire', async () => {
696
716
  const keys = [];
697
717
  const tx = this._db.transaction();
698
718
  for await (const row of this._db.find(LOCAL_MESH_MEMBERSHIP)) {
@@ -709,7 +729,7 @@ class LocalStore {
709
729
  });
710
730
  }
711
731
  markKicked(key) {
712
- return this._locked(async () => {
732
+ return this._locked('markKicked', async () => {
713
733
  const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
714
734
  if (!existing) {
715
735
  return;
@@ -720,7 +740,7 @@ class LocalStore {
720
740
  });
721
741
  }
722
742
  restoreMesh(key) {
723
- return this._locked(async () => {
743
+ return this._locked('restoreMesh', async () => {
724
744
  const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
725
745
  if (!existing) {
726
746
  return;
@@ -741,7 +761,7 @@ class LocalStore {
741
761
  return this._db.find(LOCAL_MESH_PURGES).toArray();
742
762
  }
743
763
  dropMesh(key, opts = {}) {
744
- return this._locked(async () => {
764
+ return this._locked('dropMesh', async () => {
745
765
  const held = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
746
766
  const purging = await this._db.get(LOCAL_MESH_PURGES, { key });
747
767
  const tx = this._db.transaction();
@@ -751,7 +771,7 @@ class LocalStore {
751
771
  });
752
772
  }
753
773
  dropLeftMeshes() {
754
- return this._locked(async () => {
774
+ return this._locked('dropLeftMeshes', async () => {
755
775
  const tx = this._db.transaction();
756
776
  for await (const row of this._db.find(LOCAL_MESH_MEMBERSHIP)) {
757
777
  const departing = await this._db.get(LOCAL_MESH_DEPARTURE, { key: row.key });
@@ -808,7 +828,7 @@ class LocalStore {
808
828
  }
809
829
  markAwaitingAdmission(key, opts) {
810
830
  const { awaitingAdmission } = opts;
811
- return this._locked(async () => {
831
+ return this._locked('markAwaitingAdmission', async () => {
812
832
  const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
813
833
  const settled = awaitingAdmission || !existing?.bootKey;
814
834
  if (!existing || (!!existing.awaitingAdmission === awaitingAdmission && settled)) {
@@ -823,8 +843,22 @@ class LocalStore {
823
843
  await tx.flush();
824
844
  });
825
845
  }
846
+ recordJoinHeads(key, joinHeads) {
847
+ return this._locked('recordJoinHeads', async () => {
848
+ const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
849
+ if (!existing) {
850
+ return;
851
+ }
852
+ const tx = this._db.transaction();
853
+ await tx.insert(LOCAL_MESH_MEMBERSHIP, {
854
+ ...existing,
855
+ joinHeads: [...joinHeads]
856
+ });
857
+ await tx.flush();
858
+ });
859
+ }
826
860
  markJoinedUnder(key, joinedAt) {
827
- return this._locked(async () => {
861
+ return this._locked('markJoinedUnder', async () => {
828
862
  const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
829
863
  if (!existing || existing.joinedAt === joinedAt) {
830
864
  return;
@@ -838,7 +872,7 @@ class LocalStore {
838
872
  return (await this._membership(key))?.joinedAt || null;
839
873
  }
840
874
  setMeshRole(key, role) {
841
- return this._locked(async () => {
875
+ return this._locked('setMeshRole', async () => {
842
876
  const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
843
877
  if (!existing || existing.role === role) {
844
878
  return;
@@ -852,7 +886,7 @@ class LocalStore {
852
886
  return !!(await this._membership(key))?.awaitingAdmission;
853
887
  }
854
888
  markMeshMigrated(key, migratedAt) {
855
- return this._locked(async () => {
889
+ return this._locked('markMeshMigrated', async () => {
856
890
  const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
857
891
  if (!existing) {
858
892
  return;
@@ -863,7 +897,7 @@ class LocalStore {
863
897
  });
864
898
  }
865
899
  adoptAccountMesh(deviceId, key, { account, keepName }) {
866
- return this._locked(async () => {
900
+ return this._locked('adoptAccountMesh', async () => {
867
901
  const departed = [];
868
902
  for await (const row of this._db.find(LOCAL_MESH_MEMBERSHIP)) {
869
903
  if (!b4a.equals(row.key, key) && !row.leftAt) {
@@ -948,6 +982,6 @@ class LocalStore {
948
982
  this._db.unwatch(listener);
949
983
  }
950
984
  async close() {
951
- await this._locked(() => this._db.close());
985
+ await this._locked('close', () => this._db.close());
952
986
  }
953
987
  }
@@ -1,6 +1,6 @@
1
1
  import type HyperDB from 'hyperdb';
2
2
  export declare const RUN_LOG_RETENTION_MS: number;
3
- type Locked = <T>(fn: () => Promise<T>) => Promise<T>;
3
+ type Locked = <T>(op: string, fn: () => Promise<T>) => Promise<T>;
4
4
  export interface RunLogStep {
5
5
  readonly seq: number;
6
6
  readonly expectedLength: number;