@qvac/core 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/.claude/skills/compaction/SKILL.md +9 -4
  2. package/.claude/skills/pr-create/SKILL.md +24 -3
  3. package/.claude/skills/pr-review/SKILL.md +248 -40
  4. package/CLAUDE.md +1 -3
  5. package/README.md +3 -1
  6. package/dist-lib/client.js +1 -1
  7. package/dist-lib/index.js +8 -8
  8. package/dist-lib/lib/api/agents.d.ts +1 -1
  9. package/dist-lib/lib/api/agents.js +10 -9
  10. package/dist-lib/lib/api/app-config.js +1 -1
  11. package/dist-lib/lib/api/approval-rules.js +9 -5
  12. package/dist-lib/lib/api/attachments.js +25 -3
  13. package/dist-lib/lib/api/chat-groups.d.ts +1 -1
  14. package/dist-lib/lib/api/chat-groups.js +5 -4
  15. package/dist-lib/lib/api/chat.js +8 -8
  16. package/dist-lib/lib/api/chunks.js +11 -11
  17. package/dist-lib/lib/api/config.js +1 -1
  18. package/dist-lib/lib/api/custom-models.js +2 -2
  19. package/dist-lib/lib/api/devices.d.ts +1 -1
  20. package/dist-lib/lib/api/devices.js +9 -9
  21. package/dist-lib/lib/api/diagnostics.js +1 -1
  22. package/dist-lib/lib/api/effective-ctx-size.js +1 -1
  23. package/dist-lib/lib/api/execution.js +4 -4
  24. package/dist-lib/lib/api/files.js +2 -2
  25. package/dist-lib/lib/api/index.d.ts +1 -0
  26. package/dist-lib/lib/api/index.js +33 -33
  27. package/dist-lib/lib/api/instrument.js +1 -1
  28. package/dist-lib/lib/api/knowledge.js +4 -4
  29. package/dist-lib/lib/api/logs.js +1 -1
  30. package/dist-lib/lib/api/members.d.ts +4 -1
  31. package/dist-lib/lib/api/members.js +88 -18
  32. package/dist-lib/lib/api/mesh.d.ts +13 -3
  33. package/dist-lib/lib/api/mesh.js +25 -2
  34. package/dist-lib/lib/api/model-download.js +1 -1
  35. package/dist-lib/lib/api/network.js +1 -1
  36. package/dist-lib/lib/api/notifications.js +3 -3
  37. package/dist-lib/lib/api/rag.js +7 -7
  38. package/dist-lib/lib/api/sync.js +1 -1
  39. package/dist-lib/lib/api/tool-activity.js +4 -4
  40. package/dist-lib/lib/api/tool-configs.js +5 -5
  41. package/dist-lib/lib/api/watchable.js +1 -1
  42. package/dist-lib/lib/assistant/fetch-body.d.ts +5 -0
  43. package/dist-lib/lib/assistant/fetch-body.js +36 -0
  44. package/dist-lib/lib/assistant/harness.d.ts +225 -0
  45. package/dist-lib/lib/assistant/harness.js +154 -0
  46. package/dist-lib/lib/assistant/history.d.ts +32 -0
  47. package/dist-lib/lib/assistant/history.js +232 -0
  48. package/dist-lib/lib/assistant/message.d.ts +45 -0
  49. package/dist-lib/lib/assistant/message.js +47 -0
  50. package/dist-lib/lib/assistant/skill-encode.d.ts +21 -0
  51. package/dist-lib/lib/assistant/skill-encode.js +71 -0
  52. package/dist-lib/lib/assistant-client.js +2 -2
  53. package/dist-lib/lib/assistant-tree.js +10 -4
  54. package/dist-lib/lib/assistant.d.ts +25 -285
  55. package/dist-lib/lib/assistant.js +250 -637
  56. package/dist-lib/lib/audio-format.js +2 -2
  57. package/dist-lib/lib/client.js +2 -2
  58. package/dist-lib/lib/collabora/convert.js +1 -1
  59. package/dist-lib/lib/collabora/entry.js +1 -1
  60. package/dist-lib/lib/collabora/worker.js +1 -1
  61. package/dist-lib/lib/compaction.d.ts +1 -2
  62. package/dist-lib/lib/compaction.js +8 -6
  63. package/dist-lib/lib/constants.js +1 -1
  64. package/dist-lib/lib/core/account-recovery.d.ts +19 -0
  65. package/dist-lib/lib/core/account-recovery.js +50 -0
  66. package/dist-lib/lib/core/agent.js +8 -4
  67. package/dist-lib/lib/core/app-build.d.ts +1 -1
  68. package/dist-lib/lib/core/approval-rules.d.ts +1 -0
  69. package/dist-lib/lib/core/approval-rules.js +3 -1
  70. package/dist-lib/lib/core/archived-mesh.d.ts +25 -0
  71. package/dist-lib/lib/core/archived-mesh.js +162 -0
  72. package/dist-lib/lib/core/chat-activity.js +1 -1
  73. package/dist-lib/lib/core/chat-group.d.ts +1 -0
  74. package/dist-lib/lib/core/chat-group.js +24 -4
  75. package/dist-lib/lib/core/chat-search.js +2 -2
  76. package/dist-lib/lib/core/chat.js +5 -5
  77. package/dist-lib/lib/core/chunk.d.ts +1 -1
  78. package/dist-lib/lib/core/chunk.js +4 -4
  79. package/dist-lib/lib/core/contract/agents.js +1 -1
  80. package/dist-lib/lib/core/contract/approval-rules.js +6 -4
  81. package/dist-lib/lib/core/contract/attestations.js +1 -1
  82. package/dist-lib/lib/core/contract/chat-group.js +1 -1
  83. package/dist-lib/lib/core/contract/chat.js +1 -1
  84. package/dist-lib/lib/core/contract/chunks.js +2 -2
  85. package/dist-lib/lib/core/contract/compute.d.ts +11 -0
  86. package/dist-lib/lib/core/contract/compute.js +45 -0
  87. package/dist-lib/lib/core/contract/devices.js +16 -3
  88. package/dist-lib/lib/core/contract/index.d.ts +3 -1
  89. package/dist-lib/lib/core/contract/index.js +19 -16
  90. package/dist-lib/lib/core/contract/indexing.js +2 -2
  91. package/dist-lib/lib/core/contract/joined-meshes.js +1 -1
  92. package/dist-lib/lib/core/contract/knowledge.js +2 -2
  93. package/dist-lib/lib/core/contract/members.js +2 -2
  94. package/dist-lib/lib/core/contract/seal.d.ts +2 -0
  95. package/dist-lib/lib/core/contract/seal.js +8 -0
  96. package/dist-lib/lib/core/contract/seed-defaults.js +1 -1
  97. package/dist-lib/lib/core/contract/tool-activity.js +1 -1
  98. package/dist-lib/lib/core/contract/tool-configs.js +3 -3
  99. package/dist-lib/lib/core/contract/writers.js +66 -42
  100. package/dist-lib/lib/core/departures.js +1 -1
  101. package/dist-lib/lib/core/device-invites.js +1 -1
  102. package/dist-lib/lib/core/document-attachment.js +2 -2
  103. package/dist-lib/lib/core/files/attachments.js +3 -3
  104. package/dist-lib/lib/core/files/index.d.ts +2 -2
  105. package/dist-lib/lib/core/files/index.js +19 -19
  106. package/dist-lib/lib/core/files/knowledge.js +3 -3
  107. package/dist-lib/lib/core/files/preview/image.js +1 -1
  108. package/dist-lib/lib/core/files/preview/index.js +6 -6
  109. package/dist-lib/lib/core/files/processing/claims.js +1 -1
  110. package/dist-lib/lib/core/files/processing/document.js +5 -5
  111. package/dist-lib/lib/core/files/processing/index.js +8 -8
  112. package/dist-lib/lib/core/files/processing/ownership.js +1 -1
  113. package/dist-lib/lib/core/files/processing/protocol.js +3 -3
  114. package/dist-lib/lib/core/files/processing/source.js +1 -1
  115. package/dist-lib/lib/core/files/rag/artifact/codec.js +1 -1
  116. package/dist-lib/lib/core/files/rag/artifact/id.js +1 -1
  117. package/dist-lib/lib/core/files/rag/artifact/types.d.ts +4 -4
  118. package/dist-lib/lib/core/files/rag/build.js +2 -2
  119. package/dist-lib/lib/core/files/rag/chunk/chunking.js +2 -2
  120. package/dist-lib/lib/core/files/rag/document-types.d.ts +3 -3
  121. package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +9 -9
  122. package/dist-lib/lib/core/files/rag/extract/extract.js +7 -7
  123. package/dist-lib/lib/core/files/rag/extract/html-text.js +1 -1
  124. package/dist-lib/lib/core/files/rag/extract/office-collabora.js +2 -2
  125. package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +1 -1
  126. package/dist-lib/lib/core/files/rag/extract/pdf-text.js +1 -1
  127. package/dist-lib/lib/core/files/rag/extract/text-decoding.js +1 -1
  128. package/dist-lib/lib/core/files/rag/extract/types.d.ts +2 -2
  129. package/dist-lib/lib/core/files/rag/index.js +22 -22
  130. package/dist-lib/lib/core/files/rag/load.js +5 -5
  131. package/dist-lib/lib/core/files/rag/policy.js +2 -2
  132. package/dist-lib/lib/core/files/rag/produce.js +5 -5
  133. package/dist-lib/lib/core/files/rag/retrieval/coverage.js +2 -2
  134. package/dist-lib/lib/core/files/rag/retrieval/diversity.js +1 -1
  135. package/dist-lib/lib/core/files/rag/retrieval/floor.js +2 -2
  136. package/dist-lib/lib/core/files/rag/retrieval/format.js +1 -1
  137. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +18 -11
  138. package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +5 -5
  139. package/dist-lib/lib/core/files/rag/retrieval/scoring.js +2 -2
  140. package/dist-lib/lib/core/files/rag/retrieval/search.js +4 -4
  141. package/dist-lib/lib/core/files/rag/retrieval/selection.js +2 -2
  142. package/dist-lib/lib/core/files/rag/retrieval/sources.js +2 -2
  143. package/dist-lib/lib/core/files/rag/retrieval/terms.js +1 -1
  144. package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +1 -1
  145. package/dist-lib/lib/core/files/records/chunks.js +1 -1
  146. package/dist-lib/lib/core/files/records/index.js +8 -8
  147. package/dist-lib/lib/core/files/records/knowledge.js +2 -2
  148. package/dist-lib/lib/core/files/records/output.js +1 -1
  149. package/dist-lib/lib/core/files/records/reclaim.js +5 -5
  150. package/dist-lib/lib/core/files/records/routing.js +7 -7
  151. package/dist-lib/lib/core/files/store/blob.js +2 -2
  152. package/dist-lib/lib/core/files/store/index.js +7 -7
  153. package/dist-lib/lib/core/files/store/reference.js +2 -2
  154. package/dist-lib/lib/core/files/store/server.js +1 -1
  155. package/dist-lib/lib/core/files/store/sweep.js +1 -1
  156. package/dist-lib/lib/core/files/upload-input.js +2 -2
  157. package/dist-lib/lib/core/files/upload.d.ts +1 -1
  158. package/dist-lib/lib/core/files/upload.js +6 -6
  159. package/dist-lib/lib/core/harness-loan.d.ts +29 -0
  160. package/dist-lib/lib/core/harness-loan.js +187 -0
  161. package/dist-lib/lib/core/helpers/index.d.ts +2 -1
  162. package/dist-lib/lib/core/helpers/index.js +4 -4
  163. package/dist-lib/lib/core/hosted-agents.js +2 -2
  164. package/dist-lib/lib/core/identity.d.ts +2 -0
  165. package/dist-lib/lib/core/identity.js +4 -2
  166. package/dist-lib/lib/core/invite.d.ts +1 -0
  167. package/dist-lib/lib/core/invite.js +4 -2
  168. package/dist-lib/lib/core/local/index.d.ts +12 -3
  169. package/dist-lib/lib/core/local/index.js +75 -16
  170. package/dist-lib/lib/core/membership.d.ts +3 -0
  171. package/dist-lib/lib/core/membership.js +15 -1
  172. package/dist-lib/lib/core/mesh-seed-handoff.js +1 -1
  173. package/dist-lib/lib/core/mesh.d.ts +9 -3
  174. package/dist-lib/lib/core/mesh.js +41 -26
  175. package/dist-lib/lib/core/migrations/agent-catalog.js +1 -1
  176. package/dist-lib/lib/core/migrations/index.js +5 -3
  177. package/dist-lib/lib/core/migrations/membership.js +2 -2
  178. package/dist-lib/lib/core/migrations/seal.d.ts +3 -0
  179. package/dist-lib/lib/core/migrations/seal.js +30 -0
  180. package/dist-lib/lib/core/next-frame.js +1 -1
  181. package/dist-lib/lib/core/notification.js +1 -1
  182. package/dist-lib/lib/core/ota-config.js +1 -1
  183. package/dist-lib/lib/core/secret-handoff.js +1 -1
  184. package/dist-lib/lib/core/send.js +3 -3
  185. package/dist-lib/lib/core/skill-overlay-handoff.js +1 -1
  186. package/dist-lib/lib/core/skill-overlay-receiver.js +2 -2
  187. package/dist-lib/lib/core/skill-secrets.js +3 -3
  188. package/dist-lib/lib/core/sync/devices.js +1 -1
  189. package/dist-lib/lib/core/sync/index.js +8 -5
  190. package/dist-lib/lib/core/sync-status.js +1 -1
  191. package/dist-lib/lib/core/system-info.js +1 -1
  192. package/dist-lib/lib/core/tool-activity.js +2 -2
  193. package/dist-lib/lib/core/tool-configs.js +2 -2
  194. package/dist-lib/lib/core.d.ts +41 -3
  195. package/dist-lib/lib/core.js +525 -90
  196. package/dist-lib/lib/credential-pusher.js +4 -4
  197. package/dist-lib/lib/deadline.js +1 -1
  198. package/dist-lib/lib/fs-drive-bridge.js +4 -2
  199. package/dist-lib/lib/integrations/index.js +3 -3
  200. package/dist-lib/lib/integrations/oauth-providers.js +1 -1
  201. package/dist-lib/lib/integrations/setup-routes.d.ts +5 -5
  202. package/dist-lib/lib/integrations/setup-routes.js +3 -3
  203. package/dist-lib/lib/knowledge-search.js +1 -1
  204. package/dist-lib/lib/log.js +3 -3
  205. package/dist-lib/lib/mesh-scoped-engine.d.ts +3 -0
  206. package/dist-lib/lib/mesh-scoped-engine.js +96 -0
  207. package/dist-lib/lib/model-context.d.ts +2 -2
  208. package/dist-lib/lib/model-context.js +1 -1
  209. package/dist-lib/lib/model-download.js +6 -6
  210. package/dist-lib/lib/oauth/asana.js +3 -3
  211. package/dist-lib/lib/oauth/browser-connect.js +1 -1
  212. package/dist-lib/lib/oauth/client.js +2 -2
  213. package/dist-lib/lib/oauth/common.d.ts +1 -1
  214. package/dist-lib/lib/oauth/common.js +1 -1
  215. package/dist-lib/lib/oauth/flow-core.js +3 -3
  216. package/dist-lib/lib/oauth/flow.js +2 -2
  217. package/dist-lib/lib/oauth/google.js +4 -4
  218. package/dist-lib/lib/oauth/host.js +3 -3
  219. package/dist-lib/lib/oauth/loopback.js +1 -1
  220. package/dist-lib/lib/oauth/notion.js +3 -3
  221. package/dist-lib/lib/oauth/providers.js +1 -1
  222. package/dist-lib/lib/oauth/resolve.js +1 -1
  223. package/dist-lib/lib/oauth/spotify.js +3 -3
  224. package/dist-lib/lib/oauth/token-exchange.js +1 -1
  225. package/dist-lib/lib/oauth.client.js +2 -2
  226. package/dist-lib/lib/oauth.js +12 -12
  227. package/dist-lib/lib/run-notices.d.ts +7 -7
  228. package/dist-lib/lib/run-transcript.js +1 -1
  229. package/dist-lib/schema/build.js +12 -6
  230. package/dist-lib/schema/content.d.ts +11 -11
  231. package/dist-lib/schema/engine.js +193 -30
  232. package/dist-lib/schema/field-order.js +2 -2
  233. package/dist-lib/schema/local.js +18 -4
  234. package/dist-lib/schema/qvac.js +15 -6
  235. package/dist-lib/spec/bind.js +41 -0
  236. package/dist-lib/spec/calls.js +12 -0
  237. package/dist-lib/spec/capabilities.d.ts +36 -12
  238. package/dist-lib/spec/hrpc/hrpc.json +161 -5
  239. package/dist-lib/spec/hrpc/index.js +154 -9
  240. package/dist-lib/spec/hrpc/messages.js +549 -129
  241. package/dist-lib/spec/hyperschema/index.js +549 -129
  242. package/dist-lib/spec/hyperschema/schema.json +370 -40
  243. package/dist-lib/spec/hyperschema/types.d.ts +85 -1
  244. package/dist-lib/spec/local/hyperdb/db.json +15 -0
  245. package/dist-lib/spec/local/hyperdb/index.js +70 -1
  246. package/dist-lib/spec/local/hyperdb/messages.js +300 -117
  247. package/dist-lib/spec/local/hyperschema/index.js +97 -4
  248. package/dist-lib/spec/local/hyperschema/schema.json +58 -1
  249. package/dist-lib/spec/local/hyperschema/types.d.ts +14 -0
  250. package/dist-lib/spec/mesh/hyperdb/messages.js +393 -288
  251. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +6 -0
  252. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  253. package/dist-lib/spec/mesh/hyperdispatch/messages.js +176 -85
  254. package/dist-lib/spec/mesh/hyperschema/index.js +176 -85
  255. package/dist-lib/spec/mesh/hyperschema/schema.json +71 -21
  256. package/dist-lib/spec/mesh/hyperschema/types.d.ts +14 -1
  257. package/package.json +15 -9
  258. package/tui/README.md +7 -0
  259. package/tui/app.mjs +311 -14
  260. package/tui/lib/busy-words.mjs +57 -5
  261. package/tui/lib/export.mjs +1 -0
  262. package/tui/lib/render.mjs +9 -2
  263. package/tui/main.mjs +5 -2
@@ -10,40 +10,44 @@ import Top from 'process-top';
10
10
  import ReadyGuard from 'ready-guard';
11
11
  import ReadyResource from 'ready-resource';
12
12
  import ScopeLock from 'scope-lock';
13
- import { createApi } from "./api/index.js";
14
- import { NO_SUCH_MESH } from "./api/current-mesh.js";
15
- import { BLIND_PEER_KEYS, BLIND_RELAY_KEYS } from "./core/blind-peers.js";
16
- import { CoreBlobServer, parseBlobReferenceCoreKey, MemoryVectorIndex } from "./core/files/index.js";
17
- import { removeChatAttachments, removeChatKnowledge } from "./core/chat.js";
18
- import { createFsDriveHost } from "./core/fs-drives.js";
19
- import { sweepDriveStaging } from "./fs-drive-bridge.js";
20
- import { closeCollaboraWorker } from "./collabora/worker.js";
21
- import { decodeMeshInvite, encodeMeshInvite } from "./core/invite.js";
22
- import { openLocalStore } from "./core/local/index.js";
23
- import { getAgent, ownDefaultAgents } from "./core/agent.js";
24
- import { HostedAgents } from "./core/hosted-agents.js";
25
- import { MeshSeedHandoff } from "./core/mesh-seed-handoff.js";
26
- import { SecretHandoff } from "./core/secret-handoff.js";
27
- import { SkillOverlayHandoff } from "./core/skill-overlay-handoff.js";
28
- import { createSkillOverlayReceiver } from "./core/skill-overlay-receiver.js";
29
- import { createSkillSecretReceiver, HOST_REVOKED, NO_SUCH_AGENT, NOT_THE_HOST } from "./core/skill-secrets.js";
30
- import { attestMemberClaim, claimAttestation } from "./core/identity.js";
31
- import { attestUnattestedDevices, claimOwnMembership } from "./core/membership.js";
32
- import { openDeviceInvites } from "./core/device-invites.js";
33
- import { runMigrations } from "./core/migrations/index.js";
34
- import { advertiseDeviceVersion } from "./core/devices.js";
35
- import { OtaConfigReader, configCoreFor, resolveConfigChannel, vendoredMinSupportedVersion } from "./core/ota-config.js";
36
- import { updateRequired } from "./core/min-version.js";
37
- import { PendingDepartures } from "./core/departures.js";
38
- import { buildDefaultSeed } from "./core/helpers/index.js";
39
- import { Mesh } from "./core/mesh.js";
40
- import { raceResource } from "./race-resource.js";
41
- import { createSystemInfoSampler } from "./core/system-info.js";
42
- import { oauthStateKeyFor } from "./credential-pusher.js";
43
- import { setLogger } from "./logger.js";
13
+ import { createApi } from './api/index.js';
14
+ import { NO_SUCH_MESH } from './api/current-mesh.js';
15
+ import { BLIND_PEER_KEYS, BLIND_RELAY_KEYS } from './core/blind-peers.js';
16
+ import { CoreBlobServer, parseBlobReferenceCoreKey, MemoryVectorIndex } from './core/files/index.js';
17
+ import { removeChatAttachments, removeChatKnowledge } from './core/chat.js';
18
+ import { createFsDriveHost } from './core/fs-drives.js';
19
+ import { sweepDriveStaging } from './fs-drive-bridge.js';
20
+ import { closeCollaboraWorker } from './collabora/worker.js';
21
+ import { decodeMeshInvite, encodeMeshInvite } from './core/invite.js';
22
+ import { openLocalStore } from './core/local/index.js';
23
+ import { getAgent, ownDefaultAgents } from './core/agent.js';
24
+ import { countContents, migrateContents, withArchivedMesh } from './core/archived-mesh.js';
25
+ import { HostedAgents } from './core/hosted-agents.js';
26
+ import { HarnessLoan } from './core/harness-loan.js';
27
+ import { duplexPair } from '@qvac/harness/transport';
28
+ import { MeshSeedHandoff } from './core/mesh-seed-handoff.js';
29
+ import { SecretHandoff } from './core/secret-handoff.js';
30
+ import { SkillOverlayHandoff } from './core/skill-overlay-handoff.js';
31
+ import { createSkillOverlayReceiver } from './core/skill-overlay-receiver.js';
32
+ import { createSkillSecretReceiver, HOST_REVOKED, NO_SUCH_AGENT, NOT_THE_HOST } from './core/skill-secrets.js';
33
+ import { attestMemberClaim, claimAttestation, openIdentity } from './core/identity.js';
34
+ import { openRecoveryCore, publishRecovery, readRecovery, recoveryKeys } from './core/account-recovery.js';
35
+ import { attestUnattestedDevices, claimOwnMembership, renameFoundedMember } from './core/membership.js';
36
+ import { openDeviceInvites } from './core/device-invites.js';
37
+ import { runMigrations } from './core/migrations/index.js';
38
+ import { advertiseDeviceVersion } from './core/devices.js';
39
+ import { OtaConfigReader, configCoreFor, resolveConfigChannel, vendoredMinSupportedVersion } from './core/ota-config.js';
40
+ import { updateRequired } from './core/min-version.js';
41
+ import { PendingDepartures } from './core/departures.js';
42
+ import { buildDefaultSeed } from './core/helpers/index.js';
43
+ import { Mesh } from './core/mesh.js';
44
+ import { raceResource } from './race-resource.js';
45
+ import { createSystemInfoSampler } from './core/system-info.js';
46
+ import { oauthStateKeyFor } from './credential-pusher.js';
47
+ import { setLogger } from './logger.js';
44
48
  import { settleOnClose } from '@qvac/harness/rpc';
45
- import { openLocalSpec } from "./spec-loader.js";
46
- import { unref } from "./unref.js";
49
+ import { openLocalSpec } from './spec-loader.js';
50
+ import { unref } from './unref.js';
47
51
  import { local } from '../spec/index.js';
48
52
  const QvacState = local.getEnum('@local/qvac-state');
49
53
  const top = new Top();
@@ -54,6 +58,12 @@ const MESH_ID = /^[0-9a-f]{64}$/;
54
58
  const MESH_BELOW_FLOOR = 'Build is below the mesh floor';
55
59
  const LEAVE_HOME_REFUSED = 'Your account cannot be left while other meshes remain';
56
60
  const ROOM_WITHOUT_ACCOUNT = 'A room needs an account mesh to be recorded in';
61
+ const NO_WRITABLE_ACCOUNT = 'The account mesh is not writable';
62
+ const NOT_AN_ARCHIVED_ACCOUNT = 'Not an account this device left';
63
+ const NO_ACCOUNT_TO_RECOVER = 'This device has no account to make recoverable';
64
+ const PHRASE_NOT_OURS = 'The phrase does not derive the identity this device holds';
65
+ const NO_RECOVERY_RECORD = 'No recovery record was found for this phrase';
66
+ const RECOVERY_WAIT_MS = 30_000;
57
67
  export const MEMBER_INVITE_HOME_REFUSED = 'An account mesh cannot be invited into';
58
68
  export const DEVICE_INVITE_ROOM_REFUSED = 'Only an account mesh can take a device invite';
59
69
  export const INVITE_ACCOUNT_UNREADABLE = 'This device cannot reach its account to check';
@@ -83,6 +93,9 @@ export class Core extends ReadyResource {
83
93
  _otaConfigCore;
84
94
  _otaConfig = null;
85
95
  _configPeering = null;
96
+ _recoveryCore = null;
97
+ _recoverySigner = null;
98
+ _recoveryPeering = null;
86
99
  _localDevice;
87
100
  _blindPeerKeys;
88
101
  _blindPeeringOpts;
@@ -138,6 +151,8 @@ export class Core extends ReadyResource {
138
151
  _blobServer = null;
139
152
  _wakeup;
140
153
  _meshSeedHandoff;
154
+ _harnessLoan;
155
+ _serveLoanedHarness = null;
141
156
  _following = new Set();
142
157
  _secretHandoff;
143
158
  _skillOverlayHandoff;
@@ -245,6 +260,7 @@ export class Core extends ReadyResource {
245
260
  this._meshSeedHandoff = new MeshSeedHandoff({
246
261
  onrequest: (request, from) => this._serveMeshSeed(request, from)
247
262
  });
263
+ this._harnessLoan = new HarnessLoan({ onborrow: (from) => this._lendHarness(from) });
248
264
  this._minting = false;
249
265
  this._leaving = false;
250
266
  this._kicked = false;
@@ -325,6 +341,7 @@ export class Core extends ReadyResource {
325
341
  ragIndex: () => this._activeEntry()?.vectorIndex ?? null,
326
342
  ragEmbed: () => this._indexedEmbedder,
327
343
  platform: () => this._localDevice?.platform ?? null,
344
+ computeLender: () => this._computeLender(),
328
345
  pushSkillSecret: (request) => this.pushSkillSecret(request),
329
346
  listModels: this._hostsModelSource || this._listModels
330
347
  ? (options) => this._listModels?.(options) ?? Promise.resolve({ models: [] })
@@ -681,6 +698,8 @@ export class Core extends ReadyResource {
681
698
  await this._departures.suspend();
682
699
  if (this._configPeering)
683
700
  await this._configPeering.suspend();
701
+ if (this._recoveryPeering)
702
+ await this._recoveryPeering.suspend();
684
703
  if (this._swarm)
685
704
  await this._swarm.suspend();
686
705
  if (this._blobServer)
@@ -709,6 +728,8 @@ export class Core extends ReadyResource {
709
728
  await this._swarm.resume();
710
729
  if (this._configPeering)
711
730
  await this._configPeering.resume();
731
+ if (this._recoveryPeering)
732
+ await this._recoveryPeering.resume();
712
733
  for (const { mesh } of this._meshes.values())
713
734
  await mesh.resume();
714
735
  if (this._departures)
@@ -753,6 +774,7 @@ export class Core extends ReadyResource {
753
774
  await this._discardCandidateMesh();
754
775
  await this._departures?.close();
755
776
  this._departures = null;
777
+ await this._closeRecovery();
756
778
  await this._closeConfigPeering();
757
779
  await this._closeOtaConfig();
758
780
  await this._fsDrives?.close();
@@ -827,6 +849,7 @@ export class Core extends ReadyResource {
827
849
  const mesh = new Mesh(this.store, {
828
850
  seed: session.seed,
829
851
  key: session.baseKey ?? null,
852
+ compute: session.compute,
830
853
  deviceId,
831
854
  writerSeed: session.writerSeed,
832
855
  logger: this._log,
@@ -838,8 +861,16 @@ export class Core extends ReadyResource {
838
861
  try {
839
862
  await mesh.ready();
840
863
  await raceResource(mesh.autobee, (async () => {
841
- await mesh.appendBirthOp(deviceId, this._localDevice ?? undefined, await this._mintBirthMember(mesh, deviceId, session), { deviceKeyPair: this._deviceKeyPair }, { room });
864
+ const birth = await this._mintBirthMember(mesh, deviceId, session);
865
+ await mesh.appendBirthOp(this._deviceKeyPair, this._localDevice ?? undefined, birth?.member, undefined, { room });
842
866
  await this.local.recordMesh(deviceId, mesh.key, session, { account });
867
+ if (account && birth?.mnemonic) {
868
+ await this._publishRecovery(birth.mnemonic, {
869
+ meshKey: mesh.key,
870
+ seed: session.seed,
871
+ createdAt: Date.now()
872
+ });
873
+ }
843
874
  })(), 'mesh');
844
875
  }
845
876
  catch (err) {
@@ -858,22 +889,203 @@ export class Core extends ReadyResource {
858
889
  this._identityPublicKey = identity.publicKey;
859
890
  this._holdIdentityPhrase(mnemonic);
860
891
  return {
861
- member: { id: identity.publicKey, name: local.name, joinedAt: now, updatedAt: now },
862
- proof: identity.proof
892
+ member: {
893
+ member: {
894
+ id: identity.publicKey,
895
+ name: identity.displayName ?? local.name,
896
+ joinedAt: now,
897
+ updatedAt: now
898
+ },
899
+ proof: identity.proof
900
+ },
901
+ mnemonic
863
902
  };
864
903
  }
904
+ async publishAccountRecovery(mnemonic) {
905
+ if (!this.opened)
906
+ await this.ready();
907
+ const home = await this.local.homeMesh(this._deviceKeyPair.publicKey);
908
+ if (!home)
909
+ throw new Error(NO_ACCOUNT_TO_RECOVER);
910
+ return this._publishRecovery(mnemonic, {
911
+ meshKey: home.key,
912
+ seed: home.seed,
913
+ createdAt: Date.now()
914
+ });
915
+ }
916
+ async accountRecoverable() {
917
+ if (!this.opened)
918
+ await this.ready();
919
+ const home = await this.local.homeMesh(this._deviceKeyPair.publicKey);
920
+ return home !== null && (await this.local.readAccountRecovery(home.key)) !== null;
921
+ }
922
+ async _publishRecovery(mnemonic, record) {
923
+ const identity = await openIdentity(mnemonic);
924
+ if (!this._identityPublicKey?.equals(identity.identityPublicKey)) {
925
+ throw new Error(PHRASE_NOT_OURS);
926
+ }
927
+ const core = await this._openOwnRecoveryCore(recoveryKeys(identity));
928
+ const appended = await publishRecovery(core, record);
929
+ const held = await readRecovery(core);
930
+ if (held?.meshKey.equals(record.meshKey))
931
+ await this._markRecoverable(held, core);
932
+ this._peerRecoveryCore(core);
933
+ return appended;
934
+ }
935
+ _markRecoverable(record, core) {
936
+ return this.local.recordAccountRecovery({
937
+ meshKey: record.meshKey,
938
+ coreKey: core.key,
939
+ publishedAt: record.createdAt
940
+ });
941
+ }
942
+ async _openOwnRecoveryCore(keys) {
943
+ const signer = keys.coreKeyPair.publicKey;
944
+ if (this._recoveryCore && this._recoverySigner?.equals(signer))
945
+ return this._recoveryCore;
946
+ const core = openRecoveryCore(this.store, keys);
947
+ await core.ready();
948
+ await this._adoptRecoveryCore(core, signer);
949
+ return core;
950
+ }
951
+ async _adoptRecoveryCore(core, signer) {
952
+ const previous = this._recoveryCore;
953
+ this._recoveryCore = core;
954
+ this._recoverySigner = signer;
955
+ await previous?.close();
956
+ }
957
+ async recoverAccount(mnemonic, { timeout = RECOVERY_WAIT_MS } = {}) {
958
+ await this._awaitMesh();
959
+ const identity = await openIdentity(mnemonic);
960
+ const keys = recoveryKeys(identity);
961
+ const core = openRecoveryCore(this.store, keys);
962
+ let record;
963
+ try {
964
+ record = await this._readRecovery(core, timeout);
965
+ }
966
+ catch (err) {
967
+ await core.close();
968
+ throw err;
969
+ }
970
+ await this._meshTransitionLock.lock();
971
+ let ownsTransition = false;
972
+ try {
973
+ if (this.closing)
974
+ throw new Error('Core is closing');
975
+ if (this._leaving || this._minting)
976
+ throw new Error('Mesh transition already in progress');
977
+ ownsTransition = true;
978
+ this._minting = true;
979
+ this._notifyStatus();
980
+ await this._recoverAccount(identity, record);
981
+ await this._markRecoverable(record, core);
982
+ await this._adoptRecoveryCore(core, keys.coreKeyPair.publicKey);
983
+ }
984
+ catch (err) {
985
+ await core.close();
986
+ throw err;
987
+ }
988
+ finally {
989
+ if (ownsTransition)
990
+ this._minting = false;
991
+ this._meshTransitionLock.unlock();
992
+ this._notifyStatus();
993
+ this._departures?.flush();
994
+ }
995
+ }
996
+ async _recoverAccount(identity, record) {
997
+ const deviceId = this._deviceKeyPair.publicKey;
998
+ const pooled = this._currentMesh(record.meshKey.toString('hex'));
999
+ if (pooled?.writable) {
1000
+ if (!this._isActive(pooled))
1001
+ await this._handOffActive(pooled, this._activeEntry());
1002
+ }
1003
+ else {
1004
+ if (pooled)
1005
+ await this._retirePooledMesh(pooled);
1006
+ await this._joinMesh({ seed: record.seed, baseKey: record.meshKey, fastForward: null });
1007
+ }
1008
+ const mesh = this._currentMesh();
1009
+ if (!mesh?.key.equals(record.meshKey))
1010
+ throw new Error('the recovered account did not activate');
1011
+ if (this._identityPublicKey?.equals(identity.identityPublicKey))
1012
+ return;
1013
+ const proof = await identity.bootstrap(deviceId);
1014
+ const now = Date.now();
1015
+ await this.local.replaceIdentity({
1016
+ publicKey: identity.identityPublicKey,
1017
+ proof,
1018
+ createdAt: now
1019
+ });
1020
+ this._identityPublicKey = identity.identityPublicKey;
1021
+ await mesh.dispatch('attest-member-device', {
1022
+ deviceId,
1023
+ memberId: identity.identityPublicKey,
1024
+ proof,
1025
+ attestedAt: now
1026
+ });
1027
+ }
1028
+ async _readRecovery(core, timeout) {
1029
+ await core.ready();
1030
+ this._peerRecoveryCore(core);
1031
+ try {
1032
+ const record = await readRecovery(core, { timeout });
1033
+ if (record)
1034
+ return record;
1035
+ }
1036
+ catch (err) {
1037
+ this._log?.warn(['p2p', 'mesh'], 'no blind peer served a recovery record', err);
1038
+ }
1039
+ throw new Error(NO_RECOVERY_RECORD);
1040
+ }
1041
+ _peerRecoveryCore(core) {
1042
+ if (!this._swarm || this.closing)
1043
+ return;
1044
+ const keys = this._resolveBlindPeerKeys();
1045
+ if (keys.length === 0)
1046
+ return;
1047
+ if (!this._recoveryPeering) {
1048
+ this._recoveryPeering = new BlindPeering(this._swarm.dht, this.store, {
1049
+ pick: keys.length,
1050
+ ...this._blindPeeringOpts
1051
+ });
1052
+ }
1053
+ this._recoveryPeering.addCoreBackground(core, { keys });
1054
+ this._log?.info(['p2p', 'mesh'], 'blind peering an account recovery core');
1055
+ }
1056
+ async _closeRecovery() {
1057
+ const peering = this._recoveryPeering;
1058
+ const core = this._recoveryCore;
1059
+ this._recoveryPeering = null;
1060
+ this._recoveryCore = null;
1061
+ this._recoverySigner = null;
1062
+ await peering?.close();
1063
+ await core?.close();
1064
+ }
865
1065
  async _joinBirthMember(mesh, deviceId) {
866
1066
  const local = this._localDevice;
867
1067
  if (!local || mesh.localLength > 0)
868
1068
  return undefined;
869
1069
  const now = Date.now();
1070
+ const attestation = claimAttestation(mesh.publicKey, deviceId, mesh.localWriterKey);
1071
+ const known = await this._knownMember(mesh);
1072
+ if (known) {
1073
+ return {
1074
+ member: { id: known.id, name: known.name, joinedAt: now, updatedAt: now },
1075
+ proof: await attestMemberClaim(attestation, this._deviceKeyPair, known.proof)
1076
+ };
1077
+ }
870
1078
  const { identity, mnemonic } = await this.local.ensureIdentity(deviceId, now);
871
1079
  this._identityPublicKey = identity.publicKey;
872
1080
  this._holdIdentityPhrase(mnemonic);
873
- const attestation = claimAttestation(mesh.publicKey, deviceId, mesh.localWriterKey);
874
1081
  const proof = await attestMemberClaim(attestation, this._deviceKeyPair, identity.proof);
875
1082
  return {
876
- member: { id: identity.publicKey, name: local.name, joinedAt: now, updatedAt: now },
1083
+ member: {
1084
+ id: identity.publicKey,
1085
+ name: identity.displayName ?? local.name,
1086
+ joinedAt: now,
1087
+ updatedAt: now
1088
+ },
877
1089
  proof
878
1090
  };
879
1091
  }
@@ -1002,6 +1214,7 @@ export class Core extends ReadyResource {
1002
1214
  }
1003
1215
  await this._claimOwnMembership(mesh, context);
1004
1216
  await attestUnattestedDevices(mesh, context, this._deviceInvites);
1217
+ await this._renameFoundedMember(mesh, context);
1005
1218
  }
1006
1219
  catch (err) {
1007
1220
  this._log?.warn(['p2p', 'mesh'], 'settling membership failed', err);
@@ -1010,6 +1223,11 @@ export class Core extends ReadyResource {
1010
1223
  entry.memberLock.unlock();
1011
1224
  }
1012
1225
  }
1226
+ async _renameFoundedMember(mesh, context) {
1227
+ const identity = await this.local.readIdentity();
1228
+ if (identity)
1229
+ await renameFoundedMember(mesh, context, identity);
1230
+ }
1013
1231
  async _claimOwnMembership(mesh, context) {
1014
1232
  if (mesh.ourMemberId)
1015
1233
  return;
@@ -1025,8 +1243,13 @@ export class Core extends ReadyResource {
1025
1243
  const own = await entry.mesh.view
1026
1244
  .get('@qvac/devices', { id: deviceId })
1027
1245
  .catch(() => null);
1028
- if (own?.memberId && own.memberProof)
1029
- return { id: own.memberId, proof: own.memberProof };
1246
+ if (!own?.memberId || !own.memberProof)
1247
+ continue;
1248
+ const member = await entry.mesh.view
1249
+ .get('@qvac/members', { id: own.memberId })
1250
+ .catch(() => null);
1251
+ if (member)
1252
+ return { id: member.id, name: member.name, proof: own.memberProof };
1030
1253
  }
1031
1254
  return null;
1032
1255
  }
@@ -1289,7 +1512,7 @@ export class Core extends ReadyResource {
1289
1512
  }
1290
1513
  }
1291
1514
  async _joinParkedMesh(invite, source, deviceId) {
1292
- const session = this.local.createCandidateSession(invite.seed, invite.baseKey);
1515
+ const session = this.local.createCandidateSession(invite.seed, invite.baseKey, invite.compute);
1293
1516
  let candidate;
1294
1517
  try {
1295
1518
  candidate = await this._openCandidateMesh(invite, session);
@@ -1319,11 +1542,18 @@ export class Core extends ReadyResource {
1319
1542
  await this._retireMesh(candidate).catch((err) => this._log?.warn(['p2p', 'mesh'], 'withholding the joined mesh failed', err));
1320
1543
  return;
1321
1544
  }
1322
- await this._handOffActive(candidate, outgoing);
1545
+ if (candidate.compute) {
1546
+ this._wireMesh(this._poolEntry(candidate));
1547
+ this._bringMeshOnline(candidate);
1548
+ this._notifyStatus();
1549
+ }
1550
+ else {
1551
+ await this._handOffActive(candidate, outgoing);
1552
+ }
1323
1553
  void this._departures?.drop(candidate.key).catch(noop);
1324
1554
  void this._advertiseDeviceProfile(candidate, deviceId);
1325
1555
  void this._settleMembership(candidate, { migrate: true });
1326
- if (invite.memberInvite) {
1556
+ if (invite.memberInvite && !candidate.compute) {
1327
1557
  void this._recordJoinedRoom(candidate.key);
1328
1558
  void this._seedMemberDefaults(candidate);
1329
1559
  }
@@ -1333,13 +1563,11 @@ export class Core extends ReadyResource {
1333
1563
  const account = (await this._homeMeshKey()) ?? source?.key;
1334
1564
  const rows = (await this.local.listMeshes()).filter((row) => !row.key.equals(joined));
1335
1565
  const rooms = rows.filter((row) => !account?.equals(row.key));
1336
- const registry = account ? await this._accountMesh() : null;
1337
- if (registry)
1338
- for (const room of rooms)
1339
- await this._releaseJoinedRoom(room.key, registry);
1566
+ if (account)
1567
+ await this._accountMesh();
1340
1568
  for (const room of rooms)
1341
1569
  await this._departIfPooled(room.key, 'room');
1342
- await this.local.adoptHomeMesh(this._deviceKeyPair.publicKey, joined);
1570
+ await this.local.adoptHomeMesh(this._deviceKeyPair.publicKey, joined, { account });
1343
1571
  if (account)
1344
1572
  await this._departIfPooled(account, 'account');
1345
1573
  }
@@ -1377,7 +1605,10 @@ export class Core extends ReadyResource {
1377
1605
  if (!this._isPooled(mesh) || (await this._hasOwnDefaultAgent(mesh)))
1378
1606
  return;
1379
1607
  const deviceId = this._deviceKeyPair.publicKey;
1380
- await mesh.dispatch('seed-defaults', buildDefaultSeed({ id: deviceId, recommendedModelName: local.recommendedModelName }, []));
1608
+ const member = mesh.ourMemberId
1609
+ ? await mesh.view.get('@qvac/members', { id: mesh.ourMemberId })
1610
+ : null;
1611
+ await mesh.dispatch('seed-defaults', buildDefaultSeed({ id: deviceId, recommendedModelName: local.recommendedModelName }, [], member?.name ?? local.name));
1381
1612
  }
1382
1613
  catch (error) {
1383
1614
  this._log?.warn(['p2p', 'mesh'], 'seeding this member defaults in the room failed', error);
@@ -1450,6 +1681,7 @@ export class Core extends ReadyResource {
1450
1681
  const candidate = new Mesh(this.store, {
1451
1682
  seed: session.seed,
1452
1683
  key: session.baseKey ?? null,
1684
+ compute: session.compute,
1453
1685
  deviceId: this._deviceKeyPair.publicKey,
1454
1686
  writerSeed: session.writerSeed,
1455
1687
  logger: this._log,
@@ -1486,13 +1718,10 @@ export class Core extends ReadyResource {
1486
1718
  const member = invite.memberInvite
1487
1719
  ? await this._joinBirthMember(candidate, this._deviceKeyPair.publicKey)
1488
1720
  : undefined;
1489
- const claim = {
1490
- deviceKeyPair: this._deviceKeyPair,
1491
- ...(member || !invite.memberId
1492
- ? {}
1493
- : { memberId: invite.memberId, inviteNonce: invite.inviteNonce })
1494
- };
1495
- await candidate.appendBirthOp(this._deviceKeyPair.publicKey, this._localDevice ?? undefined, member, claim);
1721
+ const claim = member || !invite.memberId
1722
+ ? undefined
1723
+ : { memberId: invite.memberId, inviteNonce: invite.inviteNonce };
1724
+ await candidate.appendBirthOp(this._deviceKeyPair, this._localDevice ?? undefined, member, claim);
1496
1725
  this._throwIfJoinCanceled();
1497
1726
  if (!candidate.key.equals(invite.baseKey)) {
1498
1727
  throw new Error('Device is not permitted to join the invited mesh');
@@ -1587,7 +1816,9 @@ export class Core extends ReadyResource {
1587
1816
  entry.handlers = handlers;
1588
1817
  mesh.on('kicked', () => this._onKicked(mesh));
1589
1818
  mesh.on('unattested-device', () => void this._settleMembership(mesh));
1819
+ mesh.on('members-dirty', () => void this._revalidateLoans());
1590
1820
  mesh.on('rooms-dirty', () => void this._followJoinedRooms(mesh));
1821
+ mesh.on('membership-tallied', () => this._notifyStatus());
1591
1822
  mesh.on('membership', (own) => {
1592
1823
  void this._recordMemberProof(mesh, own);
1593
1824
  void this._followJoinedRooms(mesh);
@@ -1881,21 +2112,81 @@ export class Core extends ReadyResource {
1881
2112
  await this.ready();
1882
2113
  const home = await this._homeMeshKey();
1883
2114
  const rows = await this.local.listMeshes();
1884
- const labels = await this._meshLabels(home);
1885
- return { meshes: rows.map((row) => this._meshEntry(row, home, labels)) };
1886
- }
1887
- async _meshLabels(home) {
1888
- const labels = new Map();
1889
2115
  const registry = home ? this._currentMesh(home.toString('hex')) : null;
1890
- const ours = registry?.ourMemberId;
1891
- if (!registry || !ours)
1892
- return labels;
1893
- for await (const room of registry.view.find(JOINED_MESHES)) {
1894
- if (room.label && room.memberId.equals(ours)) {
1895
- labels.set(room.meshKey.toString('hex'), room.label);
2116
+ const rooms = registry ? await this._ownRooms(registry) : new Map();
2117
+ return { meshes: rows.map((row) => this._meshEntry(row, home, rooms)) };
2118
+ }
2119
+ async listArchivedMeshes() {
2120
+ if (!this.opened)
2121
+ await this.ready();
2122
+ const rows = await this.local.listArchivedMeshes();
2123
+ return {
2124
+ meshes: rows.map((row) => ({
2125
+ meshId: row.key.toString('hex'),
2126
+ leftAt: row.leftAt,
2127
+ wasHome: row.wasHome,
2128
+ migratedAt: row.migratedAt
2129
+ }))
2130
+ };
2131
+ }
2132
+ async archivedMeshContents(meshId) {
2133
+ if (!this.opened)
2134
+ await this.ready();
2135
+ const row = await this._archivedRow(meshId);
2136
+ const home = await this._homeMeshKey();
2137
+ const account = home ? this._currentMesh(home.toString('hex')) : null;
2138
+ const counts = await this._withArchivedMesh(row, (mesh) => countContents(mesh, account));
2139
+ return { meshId, ...counts };
2140
+ }
2141
+ async migrateArchivedMesh(meshId) {
2142
+ if (!this.opened)
2143
+ await this.ready();
2144
+ await this._meshTransitionLock.lock();
2145
+ try {
2146
+ if (this.closing)
2147
+ throw new Error('Core is closing');
2148
+ const row = await this._archivedRow(meshId);
2149
+ if (row.migratedAt) {
2150
+ const none = { chats: 0, agents: 0, knowledge: 0 };
2151
+ return { meshId, migrated: false, migratedAt: row.migratedAt, ...none };
1896
2152
  }
2153
+ const account = await this._accountMesh();
2154
+ if (!account)
2155
+ throw new Error(NO_WRITABLE_ACCOUNT);
2156
+ const counts = await this._withArchivedMesh(row, (mesh) => migrateContents(mesh, account));
2157
+ const migratedAt = Date.now();
2158
+ await this.local.markMeshMigrated(row.key, migratedAt);
2159
+ return { meshId, migrated: true, migratedAt, ...counts };
2160
+ }
2161
+ finally {
2162
+ this._meshTransitionLock.unlock();
2163
+ }
2164
+ }
2165
+ async _archivedRow(meshId) {
2166
+ const key = this._meshKeyOf(meshId);
2167
+ const row = (await this.local.listArchivedMeshes()).find((row) => row.key.equals(key));
2168
+ if (!row)
2169
+ throw new Error(`${NO_SUCH_MESH}: ${meshId}`);
2170
+ if (!row.wasHome)
2171
+ throw new Error(`${NOT_AN_ARCHIVED_ACCOUNT}: ${meshId}`);
2172
+ return row;
2173
+ }
2174
+ _withArchivedMesh(row, fn) {
2175
+ const pooled = this._currentMesh(row.key.toString('hex'));
2176
+ if (pooled)
2177
+ return fn(pooled);
2178
+ return withArchivedMesh(this.store, row, { storage: this.storage, deviceId: this._deviceKeyPair.publicKey, logger: this._log }, fn);
2179
+ }
2180
+ async _ownRooms(registry) {
2181
+ const rooms = new Map();
2182
+ const ours = registry.ourMemberId;
2183
+ if (!ours)
2184
+ return rooms;
2185
+ for await (const room of registry.view.find(JOINED_MESHES)) {
2186
+ if (!room.leftAt && room.memberId.equals(ours))
2187
+ rooms.set(room.meshKey.toString('hex'), room);
1897
2188
  }
1898
- return labels;
2189
+ return rooms;
1899
2190
  }
1900
2191
  async _isOwnRoomIn(registry, meshKey) {
1901
2192
  const ours = registry.ourMemberId;
@@ -1929,12 +2220,12 @@ export class Core extends ReadyResource {
1929
2220
  });
1930
2221
  this._notifyStatus();
1931
2222
  }
1932
- async createRoom({ shared = false } = {}) {
2223
+ async createRoom({ shared = false, compute = false } = {}) {
1933
2224
  if (!this.opened)
1934
2225
  await this.ready();
1935
2226
  await this._meshTransitionLock.lock();
1936
2227
  try {
1937
- return await this._mintRoom(shared);
2228
+ return await this._mintRoom(shared, undefined, compute);
1938
2229
  }
1939
2230
  finally {
1940
2231
  this._meshTransitionLock.unlock();
@@ -1957,9 +2248,11 @@ export class Core extends ReadyResource {
1957
2248
  }
1958
2249
  async _occupancyNotice(meshId) {
1959
2250
  const mesh = this._currentMesh(meshId);
1960
- const ours = mesh?.ourMemberId;
1961
2251
  if (!mesh)
1962
2252
  return undefined;
2253
+ if (!mesh.ourMemberId)
2254
+ await mesh.refreshOurMember();
2255
+ const ours = mesh.ourMemberId;
1963
2256
  const snap = mesh.view.snapshot();
1964
2257
  try {
1965
2258
  for await (const member of snap.find('@qvac/members')) {
@@ -1976,20 +2269,15 @@ export class Core extends ReadyResource {
1976
2269
  }
1977
2270
  }
1978
2271
  async _resolveSharedRoom(registry) {
1979
- const ours = registry.ourMemberId;
1980
- if (!ours)
1981
- return null;
1982
- const marked = [];
1983
- for await (const room of registry.view.find(JOINED_MESHES)) {
1984
- if (room.shared && !room.leftAt && room.memberId.equals(ours))
1985
- marked.push(room);
1986
- }
2272
+ const marked = [...(await this._ownRooms(registry)).values()].filter((room) => room.shared);
1987
2273
  if (marked.length === 0)
1988
2274
  return null;
1989
2275
  marked.sort((a, b) => a.joinedAt - b.joinedAt || Buffer.compare(a.meshKey, b.meshKey));
1990
2276
  const [winner, ...losers] = marked;
1991
2277
  for (const loser of losers)
1992
2278
  await this._unmarkSharedRoom(registry, loser);
2279
+ if (losers.length > 0)
2280
+ this._notifyStatus();
1993
2281
  return { meshId: winner.meshKey.toString('hex'), notice: unmarkedNotice(losers) };
1994
2282
  }
1995
2283
  async _unmarkSharedRoom(registry, room) {
@@ -2005,7 +2293,7 @@ export class Core extends ReadyResource {
2005
2293
  }
2006
2294
  });
2007
2295
  }
2008
- async _mintRoom(shared, resolved) {
2296
+ async _mintRoom(shared, resolved, compute = false) {
2009
2297
  if (this.closing)
2010
2298
  throw new Error('Core is closing');
2011
2299
  if (this._blockedByMinVersion())
@@ -2015,7 +2303,7 @@ export class Core extends ReadyResource {
2015
2303
  const registry = resolved ?? (await this._accountMesh());
2016
2304
  if (!registry)
2017
2305
  throw new Error(ROOM_WITHOUT_ACCOUNT);
2018
- const mesh = await this._openMesh({ new: true, room: true });
2306
+ const mesh = await this._openMesh({ new: true, room: true, compute });
2019
2307
  this._wireMesh(this._poolEntry(mesh));
2020
2308
  this._bringMeshOnline(mesh, { new: true });
2021
2309
  try {
@@ -2102,10 +2390,11 @@ export class Core extends ReadyResource {
2102
2390
  this._bringMeshOnline(mesh);
2103
2391
  return mesh;
2104
2392
  }
2105
- _meshEntry(row, home, labels) {
2393
+ _meshEntry(row, home, rooms) {
2106
2394
  const meshId = row.key.toString('hex');
2107
2395
  const mesh = this._currentMesh(meshId);
2108
2396
  const active = meshId === this._activeMeshKey;
2397
+ const room = rooms.get(meshId);
2109
2398
  return {
2110
2399
  meshId,
2111
2400
  state: this._meshEntryState(mesh, active),
@@ -2113,8 +2402,11 @@ export class Core extends ReadyResource {
2113
2402
  open: mesh !== null,
2114
2403
  active,
2115
2404
  home: !!home?.equals(row.key),
2116
- label: labels.get(meshId),
2117
- members: mesh?.membership.members ?? 0
2405
+ label: room?.label || undefined,
2406
+ members: mesh?.membership.members ?? 0,
2407
+ shared: room?.shared ?? false,
2408
+ sharedAt: room?.shared ? room.sharedAt : undefined,
2409
+ compute: row.compute ?? false
2118
2410
  };
2119
2411
  }
2120
2412
  _meshEntryState(mesh, active) {
@@ -2142,6 +2434,42 @@ export class Core extends ReadyResource {
2142
2434
  if (this._localDevice)
2143
2435
  this._localDevice = { ...this._localDevice, name };
2144
2436
  }
2437
+ async displayName() {
2438
+ const identity = await this.local.readIdentity();
2439
+ if (!identity)
2440
+ return null;
2441
+ return identity.displayName ?? (await this._accountMemberName(identity.publicKey));
2442
+ }
2443
+ async _accountMemberName(identityPublicKey) {
2444
+ const home = await this._homeMeshKey();
2445
+ const mesh = home ? this._currentMesh(home.toString('hex')) : null;
2446
+ if (!mesh)
2447
+ return null;
2448
+ const ours = mesh.ourMemberId;
2449
+ if (!ours || ours.equals(identityPublicKey))
2450
+ return null;
2451
+ const member = await mesh.view.get('@qvac/members', { id: ours });
2452
+ return member?.name ?? null;
2453
+ }
2454
+ async setDisplayName(name) {
2455
+ const displayName = name.trim();
2456
+ if (!displayName)
2457
+ throw new Error('a display name is required');
2458
+ const identity = await this.local.saveDisplayName(displayName);
2459
+ if (!identity)
2460
+ throw new Error('no identity to name: this device holds no account yet');
2461
+ const context = { deviceKeyPair: this._deviceKeyPair, log: this._log };
2462
+ for (const { mesh } of this._meshes.values()) {
2463
+ if (!mesh.writable)
2464
+ continue;
2465
+ try {
2466
+ await renameFoundedMember(mesh, context, identity);
2467
+ }
2468
+ catch (err) {
2469
+ this._log?.warn(['p2p', 'mesh'], 'naming the member in this mesh failed', err);
2470
+ }
2471
+ }
2472
+ }
2145
2473
  async saveDeviceProfileLocal(capabilityProfile, recommendedModelName, platform) {
2146
2474
  const publicKey = this.devicePublicKey;
2147
2475
  if (publicKey) {
@@ -2177,7 +2505,13 @@ export class Core extends ReadyResource {
2177
2505
  async getMeshInvite(opts = {}) {
2178
2506
  if (opts.memberInvite && opts.meshId)
2179
2507
  await this._assertRoomIsHere(opts.meshId);
2180
- const mesh = opts.meshId ? await this._openPooledMesh(opts.meshId) : await this._awaitMesh();
2508
+ if (this.closing)
2509
+ return null;
2510
+ if (!this.opened)
2511
+ await this.ready();
2512
+ const target = opts.meshId ??
2513
+ (opts.memberInvite ? null : ((await this._homeMeshKey())?.toString('hex') ?? null));
2514
+ const mesh = target ? await this._openPooledMesh(target) : await this._awaitMesh();
2181
2515
  if (!mesh)
2182
2516
  return null;
2183
2517
  const registry = await this._accountMesh();
@@ -2219,15 +2553,19 @@ export class Core extends ReadyResource {
2219
2553
  seed: mesh.seed,
2220
2554
  fastForward: head ? { key: head.key, length: head.length } : null,
2221
2555
  additionalNodes,
2222
- blindPeers: blindPeerRows.map((row) => row.key),
2556
+ blindPeers: blindPeerRows.length
2557
+ ? blindPeerRows.map((row) => row.key)
2558
+ : this._resolveBlindPeerKeys().slice(0, INVITE_BLIND_PEERS_LIMIT),
2223
2559
  memberInvite: opts.memberInvite ?? false,
2224
2560
  memberId,
2225
- inviteNonce: memberId ? await this._deviceInvites.issue() : undefined
2561
+ inviteNonce: memberId ? await this._deviceInvites.issue() : undefined,
2562
+ compute: mesh.compute
2226
2563
  };
2227
2564
  }
2228
2565
  async _closeSwarm() {
2229
2566
  this._wakeup.destroy();
2230
2567
  this._meshSeedHandoff.destroy();
2568
+ this._harnessLoan.destroy();
2231
2569
  this._secretHandoff.destroy();
2232
2570
  this._skillOverlayHandoff.destroy();
2233
2571
  if (!this._swarm)
@@ -2281,13 +2619,23 @@ export class Core extends ReadyResource {
2281
2619
  for await (const room of memberMesh.view.find(JOINED_MESHES)) {
2282
2620
  if (this.closing || !this._isPooled(memberMesh))
2283
2621
  return;
2284
- if (!room.memberId.equals(ours) || room.leftAt)
2622
+ if (!room.memberId.equals(ours))
2285
2623
  continue;
2286
2624
  const meshId = room.meshKey.toString('hex');
2287
- if (this._currentMesh(meshId) || this._following.has(meshId))
2625
+ if (this._following.has(meshId))
2288
2626
  continue;
2627
+ const held = this._currentMesh(meshId);
2289
2628
  this._following.add(meshId);
2290
2629
  try {
2630
+ if (room.leftAt) {
2631
+ if (held)
2632
+ await this._retireLeftRoom(held);
2633
+ else
2634
+ await this._archiveLeftRoomRow(room.meshKey);
2635
+ continue;
2636
+ }
2637
+ if (held)
2638
+ continue;
2291
2639
  if (await this.local.readMeshSession(room.meshKey))
2292
2640
  continue;
2293
2641
  await this._openFollowedRoom(memberMesh, room.meshKey, ours);
@@ -2300,6 +2648,30 @@ export class Core extends ReadyResource {
2300
2648
  }
2301
2649
  }
2302
2650
  }
2651
+ async _retireLeftRoom(room) {
2652
+ if (this._leaving || this._minting)
2653
+ return;
2654
+ try {
2655
+ if (await this._departureHasAudience(room)) {
2656
+ await this.local.recordDeparture(room.key, { creator: room.minted });
2657
+ }
2658
+ await this._announceDeparture(room);
2659
+ if (this._isActive(room))
2660
+ await this._replaceRevokedActiveMesh(room);
2661
+ else
2662
+ await this._departRevokedMesh(room);
2663
+ this._departures?.flush();
2664
+ }
2665
+ catch (error) {
2666
+ this._log?.warn(['p2p', 'mesh'], 'retiring a room the member left failed', error);
2667
+ }
2668
+ }
2669
+ async _archiveLeftRoomRow(meshKey) {
2670
+ if (!(await this.local.readMeshSession(meshKey)))
2671
+ return;
2672
+ await this.local.archiveMesh(meshKey);
2673
+ this._notifyStatus();
2674
+ }
2303
2675
  async _openFollowedRoom(memberMesh, meshKey, ours) {
2304
2676
  const seed = await this._requestRoomSeed(memberMesh, meshKey, ours);
2305
2677
  if (!seed)
@@ -2326,6 +2698,60 @@ export class Core extends ReadyResource {
2326
2698
  }
2327
2699
  return null;
2328
2700
  }
2701
+ registerLoanableHarness(serve) {
2702
+ this._serveLoanedHarness = serve;
2703
+ return () => {
2704
+ if (this._serveLoanedHarness === serve)
2705
+ this._serveLoanedHarness = null;
2706
+ };
2707
+ }
2708
+ borrowHarness(deviceId) {
2709
+ return this._harnessLoan.borrow(deviceId);
2710
+ }
2711
+ async _lendHarness(fromDeviceId) {
2712
+ const serve = this._serveLoanedHarness;
2713
+ if (!serve)
2714
+ return null;
2715
+ const asker = Buffer.from(fromDeviceId);
2716
+ if (!(await this._sharesComputeMesh(asker))) {
2717
+ this._log?.warn(['p2p', 'mesh'], 'loan refused: no compute mesh shared with that device');
2718
+ return null;
2719
+ }
2720
+ const [ours, theirs] = duplexPair();
2721
+ serve(ours);
2722
+ return theirs;
2723
+ }
2724
+ _revalidateLoans() {
2725
+ return this._harnessLoan.revalidate((device) => this._sharesComputeMesh(Buffer.from(device)));
2726
+ }
2727
+ async _computeLender() {
2728
+ const self = this.devicePublicKey?.toString('hex');
2729
+ const lenders = new Map();
2730
+ for (const entry of this._meshes.values()) {
2731
+ if (!entry.mesh.compute)
2732
+ continue;
2733
+ for await (const device of entry.mesh.view.find('@qvac/devices')) {
2734
+ const id = device.id.toString('hex');
2735
+ if (device.revoked || id === self)
2736
+ continue;
2737
+ lenders.set(id, device.id);
2738
+ }
2739
+ }
2740
+ const [only] = [...lenders.values()];
2741
+ return lenders.size === 1 ? only : null;
2742
+ }
2743
+ async _sharesComputeMesh(deviceId) {
2744
+ for (const entry of this._meshes.values()) {
2745
+ if (!entry.mesh.compute)
2746
+ continue;
2747
+ const device = await entry.mesh.view
2748
+ .get('@qvac/devices', { id: deviceId })
2749
+ .catch(() => null);
2750
+ if (device && !device.revoked)
2751
+ return true;
2752
+ }
2753
+ return false;
2754
+ }
2329
2755
  async _serveMeshSeed(request, fromDeviceId) {
2330
2756
  const asker = Buffer.from(fromDeviceId);
2331
2757
  if (!(await this._isOwnMemberDevice(asker))) {
@@ -2487,6 +2913,7 @@ export class Core extends ReadyResource {
2487
2913
  this._secretHandoff.addStream(conn);
2488
2914
  this._skillOverlayHandoff.addStream(conn);
2489
2915
  this._meshSeedHandoff.addStream(conn);
2916
+ this._harnessLoan.addStream(conn);
2490
2917
  for (const entry of this._meshes.values()) {
2491
2918
  entry.hostedAgents?.kick();
2492
2919
  if (entry.mesh.ourMemberId)
@@ -2545,7 +2972,15 @@ export class Core extends ReadyResource {
2545
2972
  select: (meshId) => this.selectMesh(meshId),
2546
2973
  close: (meshId) => this.closeMesh(meshId),
2547
2974
  label: (meshId, label) => this.setMeshLabel(meshId, label),
2548
- createRoom: () => this.createRoom()
2975
+ createRoom: (opts) => this.createRoom(opts),
2976
+ listArchived: () => this.listArchivedMeshes(),
2977
+ archivedContents: (meshId) => this.archivedMeshContents(meshId),
2978
+ migrateArchived: (meshId) => this.migrateArchivedMesh(meshId),
2979
+ recoverable: () => this.accountRecoverable(),
2980
+ publishRecovery: async (phrase) => void (await this.publishAccountRecovery(phrase)),
2981
+ recover: (phrase, timeout) => this.recoverAccount(phrase, { timeout }),
2982
+ displayName: () => this.displayName(),
2983
+ setDisplayName: (name) => this.setDisplayName(name)
2549
2984
  };
2550
2985
  }
2551
2986
  _networkStatusSource() {