@qvac/core 0.2.0 → 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 (265) 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 +6 -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 +7 -4
  141. package/dist-lib/lib/core/files/rag/retrieval/selection.d.ts +1 -0
  142. package/dist-lib/lib/core/files/rag/retrieval/selection.js +32 -2
  143. package/dist-lib/lib/core/files/rag/retrieval/sources.js +2 -2
  144. package/dist-lib/lib/core/files/rag/retrieval/terms.js +1 -1
  145. package/dist-lib/lib/core/files/rag/retrieval/types.d.ts +1 -0
  146. package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +1 -1
  147. package/dist-lib/lib/core/files/records/chunks.js +1 -1
  148. package/dist-lib/lib/core/files/records/index.js +8 -8
  149. package/dist-lib/lib/core/files/records/knowledge.js +2 -2
  150. package/dist-lib/lib/core/files/records/output.js +1 -1
  151. package/dist-lib/lib/core/files/records/reclaim.js +5 -5
  152. package/dist-lib/lib/core/files/records/routing.js +7 -7
  153. package/dist-lib/lib/core/files/store/blob.js +2 -2
  154. package/dist-lib/lib/core/files/store/index.js +7 -7
  155. package/dist-lib/lib/core/files/store/reference.js +2 -2
  156. package/dist-lib/lib/core/files/store/server.js +1 -1
  157. package/dist-lib/lib/core/files/store/sweep.js +1 -1
  158. package/dist-lib/lib/core/files/upload-input.js +2 -2
  159. package/dist-lib/lib/core/files/upload.d.ts +1 -1
  160. package/dist-lib/lib/core/files/upload.js +6 -6
  161. package/dist-lib/lib/core/harness-loan.d.ts +29 -0
  162. package/dist-lib/lib/core/harness-loan.js +187 -0
  163. package/dist-lib/lib/core/helpers/index.d.ts +2 -1
  164. package/dist-lib/lib/core/helpers/index.js +4 -4
  165. package/dist-lib/lib/core/hosted-agents.js +2 -2
  166. package/dist-lib/lib/core/identity.d.ts +2 -0
  167. package/dist-lib/lib/core/identity.js +4 -2
  168. package/dist-lib/lib/core/invite.d.ts +1 -0
  169. package/dist-lib/lib/core/invite.js +4 -2
  170. package/dist-lib/lib/core/local/index.d.ts +12 -3
  171. package/dist-lib/lib/core/local/index.js +75 -16
  172. package/dist-lib/lib/core/membership.d.ts +3 -0
  173. package/dist-lib/lib/core/membership.js +15 -1
  174. package/dist-lib/lib/core/mesh-seed-handoff.js +1 -1
  175. package/dist-lib/lib/core/mesh.d.ts +9 -3
  176. package/dist-lib/lib/core/mesh.js +41 -26
  177. package/dist-lib/lib/core/migrations/agent-catalog.js +1 -1
  178. package/dist-lib/lib/core/migrations/index.js +5 -3
  179. package/dist-lib/lib/core/migrations/membership.js +2 -2
  180. package/dist-lib/lib/core/migrations/seal.d.ts +3 -0
  181. package/dist-lib/lib/core/migrations/seal.js +30 -0
  182. package/dist-lib/lib/core/next-frame.js +1 -1
  183. package/dist-lib/lib/core/notification.js +1 -1
  184. package/dist-lib/lib/core/ota-config.js +1 -1
  185. package/dist-lib/lib/core/secret-handoff.js +1 -1
  186. package/dist-lib/lib/core/send.js +3 -3
  187. package/dist-lib/lib/core/skill-overlay-handoff.js +1 -1
  188. package/dist-lib/lib/core/skill-overlay-receiver.js +2 -2
  189. package/dist-lib/lib/core/skill-secrets.js +3 -3
  190. package/dist-lib/lib/core/sync/devices.js +1 -1
  191. package/dist-lib/lib/core/sync/index.js +8 -5
  192. package/dist-lib/lib/core/sync-status.js +1 -1
  193. package/dist-lib/lib/core/system-info.js +1 -1
  194. package/dist-lib/lib/core/tool-activity.js +2 -2
  195. package/dist-lib/lib/core/tool-configs.js +2 -2
  196. package/dist-lib/lib/core.d.ts +41 -3
  197. package/dist-lib/lib/core.js +525 -90
  198. package/dist-lib/lib/credential-pusher.js +4 -4
  199. package/dist-lib/lib/deadline.js +1 -1
  200. package/dist-lib/lib/fs-drive-bridge.js +4 -2
  201. package/dist-lib/lib/integrations/index.js +3 -3
  202. package/dist-lib/lib/integrations/oauth-providers.js +1 -1
  203. package/dist-lib/lib/integrations/setup-routes.d.ts +5 -5
  204. package/dist-lib/lib/integrations/setup-routes.js +3 -3
  205. package/dist-lib/lib/knowledge-search.js +1 -1
  206. package/dist-lib/lib/log.js +3 -3
  207. package/dist-lib/lib/mesh-scoped-engine.d.ts +3 -0
  208. package/dist-lib/lib/mesh-scoped-engine.js +96 -0
  209. package/dist-lib/lib/model-context.d.ts +2 -2
  210. package/dist-lib/lib/model-context.js +1 -1
  211. package/dist-lib/lib/model-download.js +6 -6
  212. package/dist-lib/lib/oauth/asana.js +3 -3
  213. package/dist-lib/lib/oauth/browser-connect.js +1 -1
  214. package/dist-lib/lib/oauth/client.js +2 -2
  215. package/dist-lib/lib/oauth/common.d.ts +1 -1
  216. package/dist-lib/lib/oauth/common.js +1 -1
  217. package/dist-lib/lib/oauth/flow-core.js +3 -3
  218. package/dist-lib/lib/oauth/flow.js +2 -2
  219. package/dist-lib/lib/oauth/google.js +4 -4
  220. package/dist-lib/lib/oauth/host.js +3 -3
  221. package/dist-lib/lib/oauth/loopback.js +1 -1
  222. package/dist-lib/lib/oauth/notion.js +3 -3
  223. package/dist-lib/lib/oauth/providers.js +1 -1
  224. package/dist-lib/lib/oauth/resolve.js +1 -1
  225. package/dist-lib/lib/oauth/spotify.js +3 -3
  226. package/dist-lib/lib/oauth/token-exchange.js +1 -1
  227. package/dist-lib/lib/oauth.client.js +2 -2
  228. package/dist-lib/lib/oauth.js +12 -12
  229. package/dist-lib/lib/run-notices.d.ts +7 -7
  230. package/dist-lib/lib/run-transcript.js +1 -1
  231. package/dist-lib/schema/build.js +12 -6
  232. package/dist-lib/schema/content.d.ts +11 -11
  233. package/dist-lib/schema/engine.js +193 -30
  234. package/dist-lib/schema/field-order.js +2 -2
  235. package/dist-lib/schema/local.js +18 -4
  236. package/dist-lib/schema/qvac.js +15 -6
  237. package/dist-lib/spec/bind.js +41 -0
  238. package/dist-lib/spec/calls.js +12 -0
  239. package/dist-lib/spec/capabilities.d.ts +36 -12
  240. package/dist-lib/spec/hrpc/hrpc.json +161 -5
  241. package/dist-lib/spec/hrpc/index.js +154 -9
  242. package/dist-lib/spec/hrpc/messages.js +549 -129
  243. package/dist-lib/spec/hyperschema/index.js +549 -129
  244. package/dist-lib/spec/hyperschema/schema.json +370 -40
  245. package/dist-lib/spec/hyperschema/types.d.ts +85 -1
  246. package/dist-lib/spec/local/hyperdb/db.json +15 -0
  247. package/dist-lib/spec/local/hyperdb/index.js +70 -1
  248. package/dist-lib/spec/local/hyperdb/messages.js +300 -117
  249. package/dist-lib/spec/local/hyperschema/index.js +97 -4
  250. package/dist-lib/spec/local/hyperschema/schema.json +58 -1
  251. package/dist-lib/spec/local/hyperschema/types.d.ts +14 -0
  252. package/dist-lib/spec/mesh/hyperdb/messages.js +393 -288
  253. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +6 -0
  254. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  255. package/dist-lib/spec/mesh/hyperdispatch/messages.js +176 -85
  256. package/dist-lib/spec/mesh/hyperschema/index.js +176 -85
  257. package/dist-lib/spec/mesh/hyperschema/schema.json +71 -21
  258. package/dist-lib/spec/mesh/hyperschema/types.d.ts +14 -1
  259. package/package.json +16 -10
  260. package/tui/README.md +7 -0
  261. package/tui/app.mjs +311 -14
  262. package/tui/lib/busy-words.mjs +57 -5
  263. package/tui/lib/export.mjs +1 -0
  264. package/tui/lib/render.mjs +9 -2
  265. package/tui/main.mjs +5 -2
@@ -1,10 +1,10 @@
1
1
  import b4a from 'b4a';
2
- import { isKnowledgeRoutedAttachment, routeAttachmentToKnowledge, removeKnowledge, syncAttachmentChunk } from "./records/index.js";
3
- import { normalizeImageForModel, IMAGE_MIMES } from "../image/normalize.js";
4
- import { detectImageMime, mapDeclaredToSniffed } from "../image/sniff.js";
5
- import { isSupportedRagDocument } from "./rag/index.js";
6
- import { appendChunk, updateChunk } from "../chunk.js";
7
- import { UploadInput } from "./upload-input.js";
2
+ import { isKnowledgeRoutedAttachment, routeAttachmentToKnowledge, removeKnowledge, syncAttachmentChunk } from './records/index.js';
3
+ import { normalizeImageForModel, IMAGE_MIMES } from '../image/normalize.js';
4
+ import { detectImageMime, mapDeclaredToSniffed } from '../image/sniff.js';
5
+ import { isSupportedRagDocument } from './rag/index.js';
6
+ import { appendChunk, updateChunk } from '../chunk.js';
7
+ import { UploadInput } from './upload-input.js';
8
8
  const MODEL_NATIVE_IMAGE_MIMES = new Set([
9
9
  'image/png',
10
10
  'image/jpeg',
@@ -0,0 +1,29 @@
1
+ import { Duplex } from 'streamx';
2
+ export declare const LOAN_UNREACHABLE = "the device lending its model is not connected";
3
+ export declare const LOAN_REFUSED = "the device would not lend its model";
4
+ export declare const LOAN_REVOKED = "the device stopped lending its model";
5
+ export declare function loanFailureNotice(error: unknown): string | null;
6
+ export interface LoanStream {
7
+ readonly remotePublicKey: Uint8Array;
8
+ readonly noiseStream: {
9
+ userData: unknown;
10
+ };
11
+ }
12
+ export interface HarnessLoanOptions {
13
+ readonly onborrow: (fromDeviceId: Uint8Array) => Promise<Duplex | null>;
14
+ }
15
+ export declare class HarnessLoan {
16
+ private readonly _opts;
17
+ private readonly _peers;
18
+ private _nextId;
19
+ constructor(opts: HarnessLoanOptions);
20
+ addStream(stream: LoanStream): void;
21
+ borrow(deviceId: string): Duplex;
22
+ revalidate(allowed: (deviceId: Uint8Array) => Promise<boolean>): Promise<void>;
23
+ destroy(): void;
24
+ private _attach;
25
+ private _serve;
26
+ private _deliver;
27
+ private _end;
28
+ private _drop;
29
+ }
@@ -0,0 +1,187 @@
1
+ import b4a from 'b4a';
2
+ import { raw, uint } from 'compact-encoding';
3
+ import Protomux, {} from 'protomux';
4
+ import { Duplex } from 'streamx';
5
+ const PROTOCOL = 'qvac/harness-loan';
6
+ function noop() { }
7
+ export const LOAN_UNREACHABLE = 'the device lending its model is not connected';
8
+ export const LOAN_REFUSED = 'the device would not lend its model';
9
+ export const LOAN_REVOKED = 'the device stopped lending its model';
10
+ export function loanFailureNotice(error) {
11
+ const message = error instanceof Error ? error.message : typeof error === 'string' ? error : '';
12
+ if (message.includes(LOAN_UNREACHABLE))
13
+ return LOAN_UNREACHABLE;
14
+ if (message.includes('CHANNEL_CLOSED'))
15
+ return LOAN_REFUSED;
16
+ return null;
17
+ }
18
+ const bytes = raw;
19
+ const frame = {
20
+ preencode(state, f) {
21
+ uint.preencode(state, f.id);
22
+ uint.preencode(state, f.mine ? 1 : 0);
23
+ bytes.preencode(state, f.data);
24
+ },
25
+ encode(state, f) {
26
+ uint.encode(state, f.id);
27
+ uint.encode(state, f.mine ? 1 : 0);
28
+ bytes.encode(state, f.data);
29
+ },
30
+ decode(state) {
31
+ const id = uint.decode(state);
32
+ const mine = uint.decode(state) === 1;
33
+ return { id, mine, data: bytes.decode(state) };
34
+ }
35
+ };
36
+ const ends = {
37
+ preencode(state, e) {
38
+ uint.preencode(state, e.id);
39
+ uint.preencode(state, e.mine ? 1 : 0);
40
+ },
41
+ encode(state, e) {
42
+ uint.encode(state, e.id);
43
+ uint.encode(state, e.mine ? 1 : 0);
44
+ },
45
+ decode(state) {
46
+ return { id: uint.decode(state), mine: uint.decode(state) === 1 };
47
+ }
48
+ };
49
+ export class HarnessLoan {
50
+ _opts;
51
+ _peers;
52
+ _nextId;
53
+ constructor(opts) {
54
+ this._opts = opts;
55
+ this._peers = new Map();
56
+ this._nextId = 1;
57
+ }
58
+ addStream(stream) {
59
+ const deviceId = b4a.toString(stream.remotePublicKey, 'hex');
60
+ if (this._peers.has(deviceId))
61
+ return;
62
+ const channel = Protomux.from(stream.noiseStream).createChannel({
63
+ protocol: PROTOCOL,
64
+ onclose: () => this._drop(deviceId)
65
+ });
66
+ if (!channel)
67
+ return;
68
+ const open = channel.addMessage({
69
+ encoding: uint,
70
+ onmessage: (id) => void this._serve(deviceId, id)
71
+ });
72
+ const data = channel.addMessage({
73
+ encoding: frame,
74
+ onmessage: (f) => this._deliver(deviceId, f)
75
+ });
76
+ const close = channel.addMessage({
77
+ encoding: ends,
78
+ onmessage: (e) => this._end(deviceId, e)
79
+ });
80
+ this._peers.set(deviceId, {
81
+ channel,
82
+ remoteKey: stream.remotePublicKey,
83
+ open,
84
+ data,
85
+ close,
86
+ borrowed: new Map(),
87
+ served: new Map()
88
+ });
89
+ channel.open();
90
+ }
91
+ borrow(deviceId) {
92
+ const peer = this._peers.get(deviceId);
93
+ if (!peer)
94
+ throw new Error(LOAN_UNREACHABLE);
95
+ const id = this._nextId;
96
+ this._nextId += 1;
97
+ const stream = this._attach(peer, id, true);
98
+ peer.open.send(id);
99
+ return stream;
100
+ }
101
+ async revalidate(allowed) {
102
+ for (const peer of [...this._peers.values()]) {
103
+ if (peer.served.size === 0)
104
+ continue;
105
+ if (await allowed(peer.remoteKey).catch(() => false))
106
+ continue;
107
+ for (const [id, stream] of [...peer.served]) {
108
+ peer.served.delete(id);
109
+ peer.close.send({ id, mine: false });
110
+ stream.destroy(new Error(LOAN_REVOKED));
111
+ }
112
+ }
113
+ }
114
+ destroy() {
115
+ for (const [deviceId, peer] of [...this._peers]) {
116
+ try {
117
+ peer.channel.close();
118
+ }
119
+ catch { }
120
+ this._drop(deviceId);
121
+ }
122
+ }
123
+ _attach(peer, id, mine) {
124
+ const held = mine ? peer.borrowed : peer.served;
125
+ const stream = new Duplex({
126
+ write: (chunk, cb) => {
127
+ peer.data.send({ id, mine, data: chunk });
128
+ cb(null);
129
+ },
130
+ final: (cb) => {
131
+ peer.close.send({ id, mine });
132
+ cb(null);
133
+ },
134
+ destroy: (cb) => {
135
+ if (held.delete(id))
136
+ peer.close.send({ id, mine });
137
+ cb(null);
138
+ }
139
+ });
140
+ held.set(id, stream);
141
+ return stream;
142
+ }
143
+ async _serve(deviceId, id) {
144
+ const peer = this._peers.get(deviceId);
145
+ if (!peer || peer.served.has(id))
146
+ return;
147
+ const stream = this._attach(peer, id, false);
148
+ const served = await this._opts.onborrow(peer.remoteKey).catch(() => null);
149
+ if (!served) {
150
+ stream.destroy();
151
+ return;
152
+ }
153
+ stream.on('error', noop);
154
+ served.on('error', noop);
155
+ stream.pipe(served).pipe(stream);
156
+ }
157
+ _deliver(deviceId, f) {
158
+ const peer = this._peers.get(deviceId);
159
+ if (!peer)
160
+ return;
161
+ const held = f.mine ? peer.served : peer.borrowed;
162
+ held.get(f.id)?.push(f.data);
163
+ }
164
+ _end(deviceId, e) {
165
+ const peer = this._peers.get(deviceId);
166
+ if (!peer)
167
+ return;
168
+ const held = e.mine ? peer.served : peer.borrowed;
169
+ const stream = held.get(e.id);
170
+ if (!stream)
171
+ return;
172
+ held.delete(e.id);
173
+ stream.push(null);
174
+ stream.destroy();
175
+ }
176
+ _drop(deviceId) {
177
+ const peer = this._peers.get(deviceId);
178
+ if (!peer)
179
+ return;
180
+ this._peers.delete(deviceId);
181
+ for (const held of [peer.borrowed, peer.served]) {
182
+ for (const stream of held.values())
183
+ stream.destroy(new Error(LOAN_UNREACHABLE));
184
+ held.clear();
185
+ }
186
+ }
187
+ }
@@ -1,5 +1,6 @@
1
1
  import type { QvacDevice, QvacSeedDefaultsOperation } from '../../../spec/mesh/hyperschema/types.d.ts';
2
2
  import type { Mesh } from '../mesh.ts';
3
- export declare function buildDefaultSeed(device: Pick<QvacDevice, 'id' | 'recommendedModelName'>, blindPeerKeys: ReadonlyArray<Buffer>): QvacSeedDefaultsOperation;
3
+ export declare const DEFAULT_AGENT_NAME = "QV.AC";
4
+ export declare function buildDefaultSeed(device: Pick<QvacDevice, 'id' | 'recommendedModelName'>, blindPeerKeys: ReadonlyArray<Buffer>, agentName?: string): QvacSeedDefaultsOperation;
4
5
  export declare function isOwnRevokedRow(mesh: Mesh, device: QvacDevice): boolean;
5
6
  export declare function isOwnKickedRow(mesh: Mesh, device: QvacDevice): boolean;
@@ -1,5 +1,5 @@
1
- import { randomId } from "../id.js";
2
- const DEFAULT_AGENT_NAME = 'QV.AC';
1
+ import { randomId } from '../id.js';
2
+ export const DEFAULT_AGENT_NAME = 'QV.AC';
3
3
  const DEFAULT_AGENT_BIO = 'You are a helpful local assistant. Be clear, practical, and concise.';
4
4
  const DEFAULT_AGENT_ICON = 'artificial-intelligence';
5
5
  const DEFAULT_FIRST_CHAT_TITLE = 'New Chat';
@@ -32,13 +32,13 @@ function seedableChat(chat) {
32
32
  updatedAt: chat.updatedAt
33
33
  };
34
34
  }
35
- export function buildDefaultSeed(device, blindPeerKeys) {
35
+ export function buildDefaultSeed(device, blindPeerKeys, agentName = DEFAULT_AGENT_NAME) {
36
36
  const now = Date.now();
37
37
  const agentId = randomId();
38
38
  return {
39
39
  agent: seedableAgent({
40
40
  id: agentId,
41
- name: DEFAULT_AGENT_NAME,
41
+ name: agentName,
42
42
  bio: DEFAULT_AGENT_BIO,
43
43
  providerDeviceId: device.id,
44
44
  modelName: device.recommendedModelName,
@@ -1,7 +1,7 @@
1
1
  import b4a from 'b4a';
2
2
  import ScopeLock from 'scope-lock';
3
- import { getAgent, listAgents } from "./agent.js";
4
- import { agentSkillValues } from "./skill-secrets.js";
3
+ import { getAgent, listAgents } from './agent.js';
4
+ import { agentSkillValues } from './skill-secrets.js';
5
5
  const SCOPE = ['p2p', 'skill-values'];
6
6
  export const LEGACY_HELD_AGENTS_KEY = 'skill-values.held-agents';
7
7
  export function heldAgentsKey(meshKey) {
@@ -1,4 +1,5 @@
1
1
  import type { KeyPair } from 'hypercore-crypto';
2
+ import type IdentityKey from 'keet-identity-key';
2
3
  export declare const MAX_PROOF_BYTES = 1024;
3
4
  export interface MintedIdentity {
4
5
  readonly publicKey: Buffer;
@@ -14,6 +15,7 @@ export interface ExpectedMemberClaim {
14
15
  readonly attestation: Buffer;
15
16
  }
16
17
  export declare function generateMnemonic(): Promise<string>;
18
+ export declare function openIdentity(mnemonic: string): Promise<IdentityKey>;
17
19
  export declare function mintIdentity(mnemonic: string, devicePublicKey: Buffer): Promise<MintedIdentity>;
18
20
  export declare function attestDeviceProof(devicePublicKey: Buffer, parent: KeyPair, parentProof: Buffer): Promise<Buffer>;
19
21
  export declare function verifyDeviceProof(proof: Buffer, expected: ExpectedDeviceProof): Promise<boolean>;
@@ -13,9 +13,11 @@ async function identityKey() {
13
13
  export async function generateMnemonic() {
14
14
  return (await identityKey()).generateMnemonic();
15
15
  }
16
+ export async function openIdentity(mnemonic) {
17
+ return (await identityKey()).from({ mnemonic });
18
+ }
16
19
  export async function mintIdentity(mnemonic, devicePublicKey) {
17
- const IdentityKey = await identityKey();
18
- const identity = await IdentityKey.from({ mnemonic });
20
+ const identity = await openIdentity(mnemonic);
19
21
  return { publicKey: identity.identityPublicKey, proof: await identity.bootstrap(devicePublicKey) };
20
22
  }
21
23
  export async function attestDeviceProof(devicePublicKey, parent, parentProof) {
@@ -12,6 +12,7 @@ export interface MeshInvite {
12
12
  readonly memberInvite?: boolean;
13
13
  readonly memberId?: Buffer;
14
14
  readonly inviteNonce?: Buffer;
15
+ readonly compute?: boolean;
15
16
  }
16
17
  export declare function encodeMeshInvite(invite: MeshInvite): string;
17
18
  export declare function decodeMeshInvite(raw: string): MeshInvite | null;
@@ -11,7 +11,8 @@ export function encodeMeshInvite(invite) {
11
11
  blindPeers: [...(invite.blindPeers ?? [])],
12
12
  memberInvite: invite.memberInvite ?? false,
13
13
  memberId: invite.memberId ?? null,
14
- inviteNonce: invite.inviteNonce ?? null
14
+ inviteNonce: invite.inviteNonce ?? null,
15
+ compute: invite.compute ?? false
15
16
  };
16
17
  return INVITE_PREFIX + z32.encode(encodeStruct(INVITE_STRUCT, payload));
17
18
  }
@@ -37,6 +38,7 @@ export function decodeMeshInvite(raw) {
37
38
  blindPeers: payload.blindPeers ?? [],
38
39
  memberInvite: payload.memberInvite ?? false,
39
40
  memberId: payload.memberId ?? undefined,
40
- inviteNonce: payload.inviteNonce ?? undefined
41
+ inviteNonce: payload.inviteNonce ?? undefined,
42
+ compute: payload.compute ?? false
41
43
  };
42
44
  }
@@ -1,11 +1,12 @@
1
1
  import CorestoreStorage from 'hypercore-storage';
2
2
  import HyperDB from 'hyperdb';
3
- import type { LocalAppConfig, LocalCapabilityProfile, LocalChatNotify, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
3
+ import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatNotify, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
4
4
  import type { DeviceMetadata } from '../mesh.ts';
5
5
  export interface ResolvedSession {
6
6
  readonly seed: Buffer;
7
7
  readonly baseKey: Buffer | undefined;
8
8
  readonly writerSeed: string | undefined;
9
+ readonly compute: boolean;
9
10
  }
10
11
  export declare function openLocalStore(storage: CorestoreStorage): LocalStore;
11
12
  declare class LocalStore {
@@ -46,8 +47,12 @@ declare class LocalStore {
46
47
  renameDevice(publicKey: Buffer, name: string): Promise<void>;
47
48
  saveDeviceProfile(publicKey: Buffer, capabilityProfile: LocalCapabilityProfile, recommendedModelName: string, platform?: string): Promise<void>;
48
49
  readIdentity(): Promise<LocalIdentity | null>;
50
+ saveDisplayName(displayName: string): Promise<LocalIdentity | null>;
49
51
  readMemberProof(meshKey: Buffer): Promise<LocalMemberProof | null>;
50
52
  recordMemberProof(link: LocalMemberProof): Promise<void>;
53
+ readAccountRecovery(meshKey: Buffer): Promise<LocalAccountRecovery | null>;
54
+ recordAccountRecovery(row: LocalAccountRecovery): Promise<void>;
55
+ replaceIdentity(identity: Omit<LocalIdentity, 'id'>): Promise<void>;
51
56
  ensureIdentity(devicePublicKey: Buffer, createdAt: number): Promise<{
52
57
  identity: LocalIdentity;
53
58
  mnemonic: string | null;
@@ -57,8 +62,9 @@ declare class LocalStore {
57
62
  baseKey?: Buffer;
58
63
  new?: boolean;
59
64
  writerSeed?: string;
65
+ compute?: boolean;
60
66
  }): Promise<ResolvedSession>;
61
- createCandidateSession(seed: Buffer, baseKey: Buffer): ResolvedSession;
67
+ createCandidateSession(seed: Buffer, baseKey: Buffer, compute?: boolean): ResolvedSession;
62
68
  private _activeMembership;
63
69
  private _membership;
64
70
  private _migrateLegacySession;
@@ -73,7 +79,10 @@ declare class LocalStore {
73
79
  departures(): Promise<LocalMeshDeparture[]>;
74
80
  deleteDeparture(key: Buffer): Promise<void>;
75
81
  archiveMesh(key: Buffer): Promise<void>;
76
- adoptHomeMesh(deviceId: Buffer, key: Buffer): Promise<void>;
82
+ markMeshMigrated(key: Buffer, migratedAt: number): Promise<void>;
83
+ adoptHomeMesh(deviceId: Buffer, key: Buffer, { account }: {
84
+ account?: Buffer | null;
85
+ }): Promise<void>;
77
86
  private _pointersAt;
78
87
  listMeshes(): Promise<LocalMeshMembership[]>;
79
88
  listArchivedMeshes(): Promise<LocalMeshMembership[]>;
@@ -2,7 +2,7 @@ import CorestoreStorage from 'hypercore-storage';
2
2
  import HyperDB from 'hyperdb';
3
3
  import crypto from 'hypercore-crypto';
4
4
  import ScopeLock from 'scope-lock';
5
- import { generateMnemonic, mintIdentity } from "../identity.js";
5
+ import { generateMnemonic, mintIdentity } from '../identity.js';
6
6
  import LocalDatabaseSpec from '../../../spec/local/hyperdb/index.js';
7
7
  const CONFIG = '@local/config';
8
8
  const ACTIVE_MESH = '@local/active-mesh';
@@ -17,6 +17,7 @@ const CUSTOM_MODEL = '@local/custom-model';
17
17
  const IDENTITY = '@local/identity';
18
18
  const IDENTITY_ID = 'identity';
19
19
  const MEMBER_PROOF = '@local/member-proof';
20
+ const ACCOUNT_RECOVERY = '@local/account-recovery';
20
21
  const MEMBERSHIP = '@local/membership';
21
22
  const MEMBERSHIP_ID = 'membership';
22
23
  const CHAT_NOTIFY = '@local/chat-notify';
@@ -29,7 +30,8 @@ function sessionOf(row) {
29
30
  return {
30
31
  seed: row.seed,
31
32
  baseKey: row.key ?? undefined,
32
- writerSeed: row.writerSeed ?? undefined
33
+ writerSeed: row.writerSeed ?? undefined,
34
+ compute: row.compute ?? false
33
35
  };
34
36
  }
35
37
  export function openLocalStore(storage) {
@@ -270,6 +272,20 @@ class LocalStore {
270
272
  readIdentity() {
271
273
  return this._db.get(IDENTITY, { id: IDENTITY_ID });
272
274
  }
275
+ saveDisplayName(displayName) {
276
+ return this._locked(async () => {
277
+ const tx = this._db.transaction();
278
+ const existing = await tx.get(IDENTITY, { id: IDENTITY_ID });
279
+ if (!existing) {
280
+ await tx.close();
281
+ return null;
282
+ }
283
+ const identity = { ...existing, displayName };
284
+ await tx.insert(IDENTITY, identity);
285
+ await tx.flush();
286
+ return identity;
287
+ });
288
+ }
273
289
  readMemberProof(meshKey) {
274
290
  return this._db.get(MEMBER_PROOF, { meshKey });
275
291
  }
@@ -283,6 +299,28 @@ class LocalStore {
283
299
  await tx.flush();
284
300
  });
285
301
  }
302
+ readAccountRecovery(meshKey) {
303
+ return this._db.get(ACCOUNT_RECOVERY, { meshKey });
304
+ }
305
+ recordAccountRecovery(row) {
306
+ return this._locked(async () => {
307
+ const tx = this._db.transaction();
308
+ await tx.insert(ACCOUNT_RECOVERY, row);
309
+ await tx.flush();
310
+ });
311
+ }
312
+ replaceIdentity(identity) {
313
+ return this._locked(async () => {
314
+ const tx = this._db.transaction();
315
+ const existing = await tx.get(IDENTITY, { id: IDENTITY_ID });
316
+ await tx.insert(IDENTITY, {
317
+ id: IDENTITY_ID,
318
+ displayName: existing?.displayName ?? null,
319
+ ...identity
320
+ });
321
+ await tx.flush();
322
+ });
323
+ }
286
324
  ensureIdentity(devicePublicKey, createdAt) {
287
325
  return this._locked(async () => {
288
326
  const existing = await this._db.get(IDENTITY, { id: IDENTITY_ID });
@@ -309,7 +347,8 @@ class LocalStore {
309
347
  return {
310
348
  seed: opts.seed,
311
349
  baseKey: opts.baseKey,
312
- writerSeed: opts.writerSeed ?? freshWriterSeed()
350
+ writerSeed: opts.writerSeed ?? freshWriterSeed(),
351
+ compute: opts.compute ?? false
313
352
  };
314
353
  }
315
354
  if (current && !opts.new)
@@ -317,14 +356,16 @@ class LocalStore {
317
356
  return {
318
357
  seed: crypto.randomBytes(32),
319
358
  baseKey: undefined,
320
- writerSeed: undefined
359
+ writerSeed: undefined,
360
+ compute: opts.compute ?? false
321
361
  };
322
362
  }
323
- createCandidateSession(seed, baseKey) {
363
+ createCandidateSession(seed, baseKey, compute = false) {
324
364
  return {
325
365
  seed,
326
366
  baseKey,
327
- writerSeed: freshWriterSeed()
367
+ writerSeed: freshWriterSeed(),
368
+ compute
328
369
  };
329
370
  }
330
371
  async _activeMembership(deviceId) {
@@ -388,7 +429,8 @@ class LocalStore {
388
429
  await tx.insert(MESH_MEMBERSHIP, {
389
430
  key,
390
431
  seed: session.seed,
391
- writerSeed: session.writerSeed
432
+ writerSeed: session.writerSeed,
433
+ compute: session.compute
392
434
  });
393
435
  if (minted) {
394
436
  await tx.insert(ACTIVE_MESH, {
@@ -445,17 +487,31 @@ class LocalStore {
445
487
  archiveMesh(key) {
446
488
  return this._locked(async () => {
447
489
  const existing = await this._db.get(MESH_MEMBERSHIP, { key });
448
- const aimed = await this._pointersAt(key);
490
+ const { cleared, home } = await this._pointersAt(key);
449
491
  const tx = this._db.transaction();
450
492
  if (existing) {
451
- await tx.insert(MESH_MEMBERSHIP, { ...existing, leftAt: Date.now() });
493
+ await tx.insert(MESH_MEMBERSHIP, {
494
+ ...existing,
495
+ leftAt: Date.now(),
496
+ wasHome: home
497
+ });
452
498
  }
453
- for (const pointer of aimed)
499
+ for (const pointer of cleared)
454
500
  await tx.insert(ACTIVE_MESH, pointer);
455
501
  await tx.flush();
456
502
  });
457
503
  }
458
- adoptHomeMesh(deviceId, key) {
504
+ markMeshMigrated(key, migratedAt) {
505
+ return this._locked(async () => {
506
+ const existing = await this._db.get(MESH_MEMBERSHIP, { key });
507
+ if (!existing)
508
+ return;
509
+ const tx = this._db.transaction();
510
+ await tx.insert(MESH_MEMBERSHIP, { ...existing, migratedAt });
511
+ await tx.flush();
512
+ });
513
+ }
514
+ adoptHomeMesh(deviceId, key, { account }) {
459
515
  return this._locked(async () => {
460
516
  const departed = [];
461
517
  for await (const row of this._db.find(MESH_MEMBERSHIP)) {
@@ -466,7 +522,8 @@ class LocalStore {
466
522
  const leftAt = Date.now();
467
523
  const tx = this._db.transaction();
468
524
  for (const row of departed) {
469
- await tx.insert(MESH_MEMBERSHIP, { ...row, leftAt });
525
+ const wasHome = !!account?.equals(row.key);
526
+ await tx.insert(MESH_MEMBERSHIP, { ...row, leftAt, wasHome });
470
527
  }
471
528
  await tx.insert(ACTIVE_MESH, {
472
529
  deviceId,
@@ -478,18 +535,20 @@ class LocalStore {
478
535
  }
479
536
  async _pointersAt(key) {
480
537
  const cleared = [];
538
+ let home = false;
481
539
  for await (const pointer of this._db.find(ACTIVE_MESH)) {
482
540
  const active = pointer.activeMeshKey?.equals(key);
483
- const home = pointer.homeMeshKey?.equals(key);
484
- if (!active && !home)
541
+ const aimed = pointer.homeMeshKey?.equals(key);
542
+ if (!active && !aimed)
485
543
  continue;
544
+ home ||= !!aimed;
486
545
  cleared.push({
487
546
  deviceId: pointer.deviceId,
488
547
  activeMeshKey: active ? null : pointer.activeMeshKey,
489
- homeMeshKey: home ? null : pointer.homeMeshKey
548
+ homeMeshKey: aimed ? null : pointer.homeMeshKey
490
549
  });
491
550
  }
492
- return cleared;
551
+ return { cleared, home };
493
552
  }
494
553
  async listMeshes() {
495
554
  const rows = [];
@@ -1,5 +1,6 @@
1
1
  import type { KeyPair } from 'hyperswarm';
2
2
  import type { Logger } from '../../index.ts';
3
+ import type { LocalIdentity } from '../../spec/local/hyperschema/types.d.ts';
3
4
  import type { QvacDevice } from '../../spec/mesh/hyperschema/types.d.ts';
4
5
  import type { DeviceInvites } from './device-invites.ts';
5
6
  import type { Mesh } from './mesh.ts';
@@ -16,6 +17,8 @@ export declare function membershipView(mesh: Mesh, deviceId: Buffer): Promise<Me
16
17
  export declare function attestUnattestedDevices(mesh: Mesh, { deviceKeyPair, log }: MembershipContext, invites: DeviceInvites): Promise<void>;
17
18
  export interface KnownMember {
18
19
  readonly id: Buffer;
20
+ readonly name: string;
19
21
  readonly proof: Buffer;
20
22
  }
21
23
  export declare function claimOwnMembership(mesh: Mesh, { deviceKeyPair, log }: MembershipContext, known: KnownMember): Promise<void>;
24
+ export declare function renameFoundedMember(mesh: Mesh, { deviceKeyPair, log }: MembershipContext, identity: LocalIdentity): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { attestDeviceProof, attestMemberClaim, claimAttestation } from "./identity.js";
1
+ import { attestDeviceProof, attestMemberClaim, claimAttestation } from './identity.js';
2
2
  export async function membershipView(mesh, deviceId) {
3
3
  const snap = mesh.view.snapshot();
4
4
  try {
@@ -62,3 +62,17 @@ export async function claimOwnMembership(mesh, { deviceKeyPair, log }, known) {
62
62
  await mesh.refreshOurMember();
63
63
  log?.info('membership', 'claimed our own member in a mesh a sibling device joined');
64
64
  }
65
+ export async function renameFoundedMember(mesh, { deviceKeyPair, log }, identity) {
66
+ if (!identity.displayName)
67
+ return;
68
+ const own = await mesh.view.get('@qvac/devices', { id: deviceKeyPair.publicKey });
69
+ if (!own?.memberId || !own.memberProof)
70
+ return;
71
+ const member = await mesh.view.get('@qvac/members', { id: own.memberId });
72
+ if (!member || member.name === identity.displayName)
73
+ return;
74
+ await mesh.dispatch('update-member', {
75
+ member: { ...member, name: identity.displayName, updatedAt: Date.now() }
76
+ });
77
+ log?.info('membership', 'the member this device founded carries its user name');
78
+ }
@@ -1,5 +1,5 @@
1
1
  import { getStruct } from '../../spec/hyperschema/index.js';
2
- import { HandoffChannel } from "./handoff-channel.js";
2
+ import { HandoffChannel } from './handoff-channel.js';
3
3
  const PROTOCOL = 'qvac/mesh-seed-handoff';
4
4
  export {};
5
5
  export const SEED_REFUSED = 'the device holding this room would not share its seed';