@qvac/core 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.claude/skills/compaction/SKILL.md +1 -1
  2. package/.claude/skills/gh-stack/SKILL.md +24 -24
  3. package/.claude/skills/gh-stack/references/commands.md +2 -2
  4. package/.claude/skills/js-house-style/SKILL.md +1 -1
  5. package/.claude/skills/pr-create/SKILL.md +46 -3
  6. package/.claude/skills/pr-review/SKILL.md +76 -7
  7. package/CLAUDE.md +3 -0
  8. package/README.md +10 -5
  9. package/dist-lib/lib/api/agents.js +3 -3
  10. package/dist-lib/lib/api/chat-groups.d.ts +1 -1
  11. package/dist-lib/lib/api/chat-groups.js +5 -3
  12. package/dist-lib/lib/api/chat.js +2 -2
  13. package/dist-lib/lib/api/current-mesh.d.ts +3 -2
  14. package/dist-lib/lib/api/current-mesh.js +4 -3
  15. package/dist-lib/lib/api/devices.js +1 -0
  16. package/dist-lib/lib/api/index.js +2 -0
  17. package/dist-lib/lib/api/members.d.ts +3 -0
  18. package/dist-lib/lib/api/members.js +23 -0
  19. package/dist-lib/lib/api/mesh.d.ts +14 -3
  20. package/dist-lib/lib/api/mesh.js +20 -3
  21. package/dist-lib/lib/api/watchable.d.ts +1 -1
  22. package/dist-lib/lib/api/watchable.js +1 -1
  23. package/dist-lib/lib/core/agent.d.ts +1 -0
  24. package/dist-lib/lib/core/agent.js +29 -1
  25. package/dist-lib/lib/core/chat-group.d.ts +4 -0
  26. package/dist-lib/lib/core/chat-group.js +43 -1
  27. package/dist-lib/lib/core/chat.d.ts +10 -0
  28. package/dist-lib/lib/core/chat.js +75 -9
  29. package/dist-lib/lib/core/contract/index.js +2 -0
  30. package/dist-lib/lib/core/contract/joined-meshes.d.ts +2 -0
  31. package/dist-lib/lib/core/contract/joined-meshes.js +41 -0
  32. package/dist-lib/lib/core/contract/members.js +68 -2
  33. package/dist-lib/lib/core/contract/writers.js +19 -3
  34. package/dist-lib/lib/core/departures.d.ts +3 -1
  35. package/dist-lib/lib/core/departures.js +6 -4
  36. package/dist-lib/lib/core/device-attestation.d.ts +8 -0
  37. package/dist-lib/lib/core/device-attestation.js +25 -0
  38. package/dist-lib/lib/core/device-invites.d.ts +9 -0
  39. package/dist-lib/lib/core/device-invites.js +40 -0
  40. package/dist-lib/lib/core/files/index.d.ts +2 -1
  41. package/dist-lib/lib/core/files/index.js +1 -1
  42. package/dist-lib/lib/core/files/store/index.d.ts +1 -0
  43. package/dist-lib/lib/core/files/store/server.d.ts +5 -4
  44. package/dist-lib/lib/core/files/store/server.js +10 -6
  45. package/dist-lib/lib/core/helpers/index.d.ts +1 -1
  46. package/dist-lib/lib/core/hosted-agents.d.ts +3 -1
  47. package/dist-lib/lib/core/hosted-agents.js +9 -3
  48. package/dist-lib/lib/core/identity.d.ts +10 -0
  49. package/dist-lib/lib/core/identity.js +45 -0
  50. package/dist-lib/lib/core/invite.d.ts +3 -0
  51. package/dist-lib/lib/core/invite.js +8 -2
  52. package/dist-lib/lib/core/local/index.d.ts +22 -7
  53. package/dist-lib/lib/core/local/index.js +202 -66
  54. package/dist-lib/lib/core/membership.d.ts +8 -2
  55. package/dist-lib/lib/core/membership.js +33 -9
  56. package/dist-lib/lib/core/mesh-seed-handoff.d.ts +17 -0
  57. package/dist-lib/lib/core/mesh-seed-handoff.js +34 -0
  58. package/dist-lib/lib/core/mesh.d.ts +12 -1
  59. package/dist-lib/lib/core/mesh.js +36 -7
  60. package/dist-lib/lib/core/migrations/index.d.ts +3 -1
  61. package/dist-lib/lib/core/migrations/index.js +2 -2
  62. package/dist-lib/lib/core/migrations/membership.js +27 -15
  63. package/dist-lib/lib/core/rank.d.ts +14 -0
  64. package/dist-lib/lib/core/rank.js +23 -0
  65. package/dist-lib/lib/core/sync/index.js +6 -0
  66. package/dist-lib/lib/core.d.ts +91 -13
  67. package/dist-lib/lib/core.js +1051 -207
  68. package/dist-lib/schema/build.js +3 -2
  69. package/dist-lib/schema/engine.js +153 -9
  70. package/dist-lib/schema/field-order.js +4 -1
  71. package/dist-lib/schema/local.js +32 -0
  72. package/dist-lib/schema/qvac.js +45 -6
  73. package/dist-lib/spec/bind.js +35 -0
  74. package/dist-lib/spec/calls.js +37 -27
  75. package/dist-lib/spec/capabilities.d.ts +30 -10
  76. package/dist-lib/spec/hrpc/hrpc.json +135 -5
  77. package/dist-lib/spec/hrpc/index.js +130 -9
  78. package/dist-lib/spec/hrpc/messages.js +408 -14
  79. package/dist-lib/spec/hyperschema/index.js +408 -14
  80. package/dist-lib/spec/hyperschema/schema.json +309 -1
  81. package/dist-lib/spec/hyperschema/types.d.ts +90 -1
  82. package/dist-lib/spec/local/hyperdb/db.json +46 -1
  83. package/dist-lib/spec/local/hyperdb/index.js +209 -2
  84. package/dist-lib/spec/local/hyperdb/messages.js +557 -90
  85. package/dist-lib/spec/local/hyperschema/index.js +240 -2
  86. package/dist-lib/spec/local/hyperschema/schema.json +120 -1
  87. package/dist-lib/spec/local/hyperschema/types.d.ts +33 -1
  88. package/dist-lib/spec/mesh/hyperdb/db.json +16 -1
  89. package/dist-lib/spec/mesh/hyperdb/index.js +71 -2
  90. package/dist-lib/spec/mesh/hyperdb/messages.js +571 -192
  91. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +13 -1
  92. package/dist-lib/spec/mesh/hyperdispatch/index.js +35 -1
  93. package/dist-lib/spec/mesh/hyperdispatch/messages.js +283 -20
  94. package/dist-lib/spec/mesh/hyperschema/index.js +283 -20
  95. package/dist-lib/spec/mesh/hyperschema/schema.json +179 -1
  96. package/dist-lib/spec/mesh/hyperschema/types.d.ts +45 -1
  97. package/package.json +5 -5
  98. package/tui/app.mjs +416 -50
  99. package/tui/boot.mjs +1 -1
  100. package/tui/lib/sidebar.mjs +3 -2
@@ -1,4 +1,4 @@
1
- import { attestDeviceProof } 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 {
@@ -11,7 +11,7 @@ export async function membershipView(mesh, deviceId) {
11
11
  if (device.id.equals(deviceId))
12
12
  own = device;
13
13
  else if (!device.revoked && !device.memberId)
14
- unattested.push(device.id);
14
+ unattested.push(device);
15
15
  }
16
16
  return { members, own, unattested };
17
17
  }
@@ -19,22 +19,46 @@ export async function membershipView(mesh, deviceId) {
19
19
  await snap.close();
20
20
  }
21
21
  }
22
- export async function attestUnattestedDevices(mesh, { deviceKeyPair, log }) {
22
+ export async function attestUnattestedDevices(mesh, { deviceKeyPair, log }, invites) {
23
23
  const { own, unattested } = await membershipView(mesh, deviceKeyPair.publicKey);
24
24
  if (!own?.memberId || !own.memberProof || unattested.length === 0)
25
25
  return;
26
+ const ours = own.memberId;
27
+ const adoptable = [];
28
+ for (const device of unattested) {
29
+ if (!device.claimedMemberId?.equals(ours))
30
+ continue;
31
+ if (await invites.redeem(device.inviteToken, device.id))
32
+ adoptable.push(device);
33
+ }
34
+ if (adoptable.length === 0)
35
+ return;
26
36
  const now = Date.now();
27
37
  const batch = mesh.batch();
28
- for (const id of unattested) {
38
+ for (const device of adoptable) {
29
39
  batch.dispatch('attest-member-device', {
30
- deviceId: id,
31
- memberId: own.memberId,
32
- proof: await attestDeviceProof(id, deviceKeyPair, own.memberProof),
40
+ deviceId: device.id,
41
+ memberId: ours,
42
+ proof: await attestDeviceProof(device.id, deviceKeyPair, own.memberProof),
33
43
  attestedAt: now
34
44
  });
35
45
  }
36
46
  await batch.flush();
37
- log?.info(['p2p', 'mesh'], 'every device we hold is attested to our member', {
38
- attested: unattested.length
47
+ log?.info(['p2p', 'mesh'], 'every device that asked for our member is attested', {
48
+ attested: adoptable.length
39
49
  });
40
50
  }
51
+ export async function claimOwnMembership(mesh, { deviceKeyPair, log }, known) {
52
+ const deviceId = deviceKeyPair.publicKey;
53
+ const own = await mesh.view.get('@qvac/devices', { id: deviceId });
54
+ if (!own || own.memberId)
55
+ return;
56
+ const member = await mesh.view.get('@qvac/members', { id: known.id });
57
+ if (!member)
58
+ return;
59
+ const attestation = claimAttestation(mesh.publicKey, deviceId, mesh.localWriterKey);
60
+ const proof = await attestMemberClaim(attestation, deviceKeyPair, known.proof);
61
+ await mesh.dispatch('join-member', { member, proof });
62
+ await mesh.refreshOurMember();
63
+ log?.info('membership', 'claimed our own member in a mesh a sibling device joined');
64
+ }
@@ -0,0 +1,17 @@
1
+ import { type HandoffStream } from './handoff-channel.ts';
2
+ import type { AssistantMeshSeedRequest } from '../../spec/hyperschema/types.d.ts';
3
+ export { type HandoffStream };
4
+ export declare const SEED_REFUSED = "the device holding this room would not share its seed";
5
+ export type MeshSeedRequest = AssistantMeshSeedRequest;
6
+ export type MeshSeedRequestHandler = (request: MeshSeedRequest, fromDeviceId: Uint8Array) => Promise<Buffer | null>;
7
+ export interface MeshSeedHandoffOptions {
8
+ readonly onrequest: MeshSeedRequestHandler;
9
+ readonly ackTimeoutMs?: number;
10
+ }
11
+ export declare class MeshSeedHandoff {
12
+ private readonly _channel;
13
+ constructor(opts: MeshSeedHandoffOptions);
14
+ addStream(stream: HandoffStream): void;
15
+ request(holderDeviceId: Uint8Array, meshKey: Buffer): Promise<Buffer | null>;
16
+ destroy(): void;
17
+ }
@@ -0,0 +1,34 @@
1
+ import { getStruct } from '../../spec/hyperschema/index.js';
2
+ import { HandoffChannel } from "./handoff-channel.js";
3
+ const PROTOCOL = 'qvac/mesh-seed-handoff';
4
+ export {};
5
+ export const SEED_REFUSED = 'the device holding this room would not share its seed';
6
+ const handoff = getStruct('@assistant/mesh-seed-handoff');
7
+ const handoffAck = getStruct('@assistant/mesh-seed-handoff-ack');
8
+ export class MeshSeedHandoff {
9
+ _channel;
10
+ constructor(opts) {
11
+ this._channel = new HandoffChannel({
12
+ protocol: PROTOCOL,
13
+ requestEncoding: handoff,
14
+ ackEncoding: handoffAck,
15
+ onrequest: opts.onrequest,
16
+ buildAck: (id, error, result) => ({
17
+ id,
18
+ error: error || (result ? undefined : SEED_REFUSED),
19
+ seed: result ?? undefined
20
+ }),
21
+ readAck: (ack) => ({ error: ack.error ?? '', result: ack.seed ?? null }),
22
+ ackTimeoutMs: opts.ackTimeoutMs
23
+ });
24
+ }
25
+ addStream(stream) {
26
+ this._channel.addStream(stream);
27
+ }
28
+ request(holderDeviceId, meshKey) {
29
+ return this._channel.send(holderDeviceId, { meshKey });
30
+ }
31
+ destroy() {
32
+ this._channel.destroy();
33
+ }
34
+ }
@@ -2,6 +2,7 @@ import Autobee, { type AutobeeChanges, type AutobeeHost, type AutobeeNode, type
2
2
  import Corestore from 'corestore';
3
3
  import HyperDB from 'hyperdb';
4
4
  import Hyperblobs from 'hyperblobs';
5
+ import type { KeyPair } from 'hypercore-crypto';
5
6
  import type Wakeup from 'protomux-wakeup';
6
7
  import ReadyResource from 'ready-resource';
7
8
  import { Files } from './files/index.ts';
@@ -46,6 +47,11 @@ export interface BirthMember {
46
47
  readonly member: QvacMember;
47
48
  readonly proof: Buffer;
48
49
  }
50
+ export interface BirthClaim {
51
+ readonly deviceKeyPair?: KeyPair;
52
+ readonly memberId?: Buffer;
53
+ readonly inviteNonce?: Buffer | null;
54
+ }
49
55
  export interface MembershipStats {
50
56
  readonly members: number;
51
57
  readonly attested: number;
@@ -92,6 +98,7 @@ export declare class Mesh extends ReadyResource {
92
98
  get devicePublicKey(): Buffer;
93
99
  get key(): Buffer;
94
100
  get encryptionKey(): Buffer;
101
+ get seed(): Buffer;
95
102
  get blindPeerKeys(): ReadonlyArray<Buffer>;
96
103
  get orphanedBlobSweepStatus(): OrphanedBlobSweepStatus;
97
104
  blindPeerStats(): Array<{
@@ -101,6 +108,7 @@ export declare class Mesh extends ReadyResource {
101
108
  uploaded: number;
102
109
  }>;
103
110
  get ourMemberId(): Buffer | null;
111
+ get ourDeviceId(): Buffer | null;
104
112
  get membership(): MembershipStats;
105
113
  refreshMembership(): Promise<void>;
106
114
  refreshOurMember(): Promise<void>;
@@ -115,13 +123,16 @@ export declare class Mesh extends ReadyResource {
115
123
  private _sweepOrphanedBlobs;
116
124
  get view(): HyperDB;
117
125
  get localWriterKey(): Buffer<ArrayBufferLike>;
126
+ get minted(): boolean;
118
127
  get writable(): boolean;
119
128
  get localLength(): number;
120
129
  dispatch(name: string, payload: unknown, opts?: {
121
130
  optimistic?: boolean;
122
131
  }): Promise<void>;
123
132
  batch(): MeshBatch;
124
- appendBirthOp(deviceId: Buffer, device?: DeviceMetadata, member?: BirthMember): Promise<void>;
133
+ appendBirthOp(deviceId: Buffer, device?: DeviceMetadata, member?: BirthMember, claim?: BirthClaim, { room }?: {
134
+ room?: boolean;
135
+ }): Promise<void>;
125
136
  get interrupted(): unknown;
126
137
  throwIfInterrupted(): void;
127
138
  waitForWritable(): Promise<void>;
@@ -12,7 +12,8 @@ import { Router, encode } from '../../spec/mesh/hyperdispatch/index.js';
12
12
  import { syncChanges } from "./sync/index.js";
13
13
  import { buildDefaultSeed, isOwnKickedRow, isOwnRevokedRow } from "./helpers/index.js";
14
14
  import { raceResource } from "../race-resource.js";
15
- import { signDeviceAttestation } from "./device-attestation.js";
15
+ import { signDeviceAttestation, signWriterClaim } from "./device-attestation.js";
16
+ import { deviceInviteToken } from "./identity.js";
16
17
  import { liveDeviceForWriter } from "./contract/activity.js";
17
18
  import { registerRoutes } from "./contract/index.js";
18
19
  import { createSyncActivity } from "./sync-status.js";
@@ -91,6 +92,9 @@ export class Mesh extends ReadyResource {
91
92
  get encryptionKey() {
92
93
  return this._encryptionKey;
93
94
  }
95
+ get seed() {
96
+ return this._seed;
97
+ }
94
98
  get blindPeerKeys() {
95
99
  return this._blindPeerKeys;
96
100
  }
@@ -111,6 +115,9 @@ export class Mesh extends ReadyResource {
111
115
  get ourMemberId() {
112
116
  return this._ourMemberId;
113
117
  }
118
+ get ourDeviceId() {
119
+ return this._deviceId;
120
+ }
114
121
  get membership() {
115
122
  return this._membership;
116
123
  }
@@ -285,6 +292,9 @@ export class Mesh extends ReadyResource {
285
292
  get localWriterKey() {
286
293
  return this.autobee.local.key;
287
294
  }
295
+ get minted() {
296
+ return this.autobee.key.equals(this.autobee.local.key);
297
+ }
288
298
  get writable() {
289
299
  return this.autobee.writable;
290
300
  }
@@ -297,7 +307,7 @@ export class Mesh extends ReadyResource {
297
307
  batch() {
298
308
  return new MeshBatch(this.autobee);
299
309
  }
300
- async appendBirthOp(deviceId, device, member) {
310
+ async appendBirthOp(deviceId, device, member, claim, { room = false } = {}) {
301
311
  if (this.autobee.local.length > 0)
302
312
  return;
303
313
  const localKey = this.autobee.local.key;
@@ -312,18 +322,37 @@ export class Mesh extends ReadyResource {
312
322
  if (member)
313
323
  birth.dispatch('mint-member', member);
314
324
  birth.dispatch('seed-defaults', buildDefaultSeed(row, this._blindPeerKeys));
315
- birth.dispatch('put-agent', { agent: buildHealthAssistant(row) });
325
+ if (!room)
326
+ birth.dispatch('put-agent', { agent: buildHealthAssistant(row) });
316
327
  }
317
328
  await birth.flush();
318
329
  }
319
330
  else if (!this.autobee.writable) {
320
331
  const signature = this.sign(localKey);
321
332
  const device = row ? claimableDevice(row) : undefined;
322
- const claim = this.batch();
323
- claim.dispatch('join', { signature, deviceId, device });
333
+ const join = this.batch();
334
+ join.dispatch('join', {
335
+ signature,
336
+ deviceId,
337
+ device,
338
+ claimedMemberId: claim?.memberId,
339
+ inviteToken: claim?.inviteNonce
340
+ ? deviceInviteToken(claim.inviteNonce, deviceId)
341
+ : undefined,
342
+ deviceSignature: claim?.deviceKeyPair && row
343
+ ? signWriterClaim(claim.deviceKeyPair.secretKey, {
344
+ meshPublicKey: this.publicKey,
345
+ deviceId,
346
+ writerKey: localKey,
347
+ joinedAt: row.joinedAt
348
+ })
349
+ : undefined
350
+ });
324
351
  if (row)
325
- claim.dispatch('attest-device', this.attestDevice(deviceId));
326
- await claim.flush({ optimistic: true });
352
+ join.dispatch('attest-device', this.attestDevice(deviceId));
353
+ if (row && member)
354
+ join.dispatch('join-member', member);
355
+ await join.flush({ optimistic: true });
327
356
  }
328
357
  await this.autobee.update();
329
358
  this.throwIfInterrupted();
@@ -2,4 +2,6 @@ import type { Mesh } from '../mesh.ts';
2
2
  import { type AgentCatalogMigrationContext } from './agent-catalog.ts';
3
3
  import { type MembershipMigrationContext } from './membership.ts';
4
4
  export type MigrationContext = MembershipMigrationContext & AgentCatalogMigrationContext;
5
- export declare function runMigrations(mesh: Mesh, context: MigrationContext): Promise<boolean>;
5
+ export declare function runMigrations(mesh: Mesh, context: MigrationContext, { catalog }?: {
6
+ catalog?: boolean;
7
+ }): Promise<boolean>;
@@ -1,7 +1,7 @@
1
1
  import { migrateAgentCatalog } from "./agent-catalog.js";
2
2
  import { migrateMembership } from "./membership.js";
3
- export async function runMigrations(mesh, context) {
3
+ export async function runMigrations(mesh, context, { catalog = true } = {}) {
4
4
  const membership = await migrateMembership(mesh, context);
5
- const agents = await migrateAgentCatalog(mesh, context);
5
+ const agents = catalog && (await migrateAgentCatalog(mesh, context));
6
6
  return membership || agents;
7
7
  }
@@ -2,25 +2,37 @@ import { attestDeviceProof } from "../identity.js";
2
2
  import { membershipView } from "../membership.js";
3
3
  export async function migrateMembership(mesh, { deviceKeyPair, deviceName, mintRoot, log }) {
4
4
  const { members, own, unattested } = await membershipView(mesh, deviceKeyPair.publicKey);
5
- if (members > 0 || !own || own.memberId)
5
+ if (!own)
6
+ return false;
7
+ const resuming = Boolean(own.memberId) && members === 1 && unattested.length > 0;
8
+ if (!resuming && (members > 0 || own.memberId))
6
9
  return false;
7
10
  const now = Date.now();
8
11
  const root = await mintRoot(own.id, now);
9
- const batch = mesh.batch();
10
- batch.dispatch('mint-member', {
11
- member: { id: root.publicKey, name: deviceName, joinedAt: now, updatedAt: now },
12
- proof: root.proof
13
- });
14
- for (const id of unattested) {
15
- batch.dispatch('attest-member-device', {
16
- deviceId: id,
17
- memberId: root.publicKey,
18
- proof: await attestDeviceProof(id, deviceKeyPair, root.proof),
19
- attestedAt: now
12
+ if (resuming && !own.memberId.equals(root.publicKey))
13
+ return false;
14
+ if (!resuming) {
15
+ await mesh.dispatch('mint-member', {
16
+ member: { id: root.publicKey, name: deviceName, joinedAt: now, updatedAt: now },
17
+ proof: root.proof
20
18
  });
19
+ await mesh.refreshOurMember();
21
20
  }
22
- await batch.flush();
23
- await mesh.refreshOurMember();
24
- log?.info(['p2p', 'mesh'], 'migrated: minted the member this mesh predates, every device we hold is attested to our member', { attested: unattested.length });
21
+ if (unattested.length > 0) {
22
+ const batch = mesh.batch();
23
+ for (const device of unattested) {
24
+ batch.dispatch('attest-member-device', {
25
+ deviceId: device.id,
26
+ memberId: root.publicKey,
27
+ proof: await attestDeviceProof(device.id, deviceKeyPair, root.proof),
28
+ attestedAt: now
29
+ });
30
+ }
31
+ await batch.flush();
32
+ }
33
+ log?.info(['p2p', 'mesh'], 'migrated: minted the member this mesh predates', {
34
+ attested: unattested.length,
35
+ resumed: resuming
36
+ });
25
37
  return true;
26
38
  }
@@ -0,0 +1,14 @@
1
+ export declare const STEP = 1000;
2
+ export interface Placement<T> {
3
+ rank: number;
4
+ respaced: Array<{
5
+ row: T;
6
+ rank: number;
7
+ }>;
8
+ }
9
+ export declare function rankBetween(anchor: number, next: number | undefined): number;
10
+ export declare function rankOnTop(top: number | undefined, now: number): number;
11
+ export declare function place<T>(siblings: readonly T[], keyOf: (row: T) => number, { at, now }: {
12
+ at: number;
13
+ now: number;
14
+ }): Placement<T>;
@@ -0,0 +1,23 @@
1
+ const FLOOR = 1;
2
+ export const STEP = 1_000;
3
+ const TOP_STEP = 1;
4
+ export function rankBetween(anchor, next) {
5
+ if (next === undefined)
6
+ return Math.max(anchor - STEP, FLOOR);
7
+ return anchor + (next - anchor) / 2;
8
+ }
9
+ export function rankOnTop(top, now) {
10
+ return top === undefined ? now : Math.max(top + TOP_STEP, now);
11
+ }
12
+ export function place(siblings, keyOf, { at, now }) {
13
+ const upper = at >= 0 ? keyOf(siblings[at]) : undefined;
14
+ const below = siblings[at + 1];
15
+ const lower = below === undefined ? undefined : keyOf(below);
16
+ const rank = upper === undefined ? rankOnTop(lower, now) : rankBetween(upper, lower);
17
+ if ((upper === undefined || rank < upper) && (lower === undefined || rank > lower)) {
18
+ return { rank, respaced: [] };
19
+ }
20
+ const top = Math.max(now, keyOf(siblings[0]));
21
+ const respaced = siblings.map((row, i) => ({ row, rank: top - (i > at ? i + 1 : i) * STEP }));
22
+ return { rank: top - (at + 1) * STEP, respaced };
23
+ }
@@ -9,6 +9,7 @@ export async function syncChanges(mesh, view, from) {
9
9
  let unattestedDevice = false;
10
10
  let membershipMoved = false;
11
11
  let agentsDirty = false;
12
+ let roomsChanged = false;
12
13
  const snap = view.db.snapshot();
13
14
  const files = new FileChanges(snap, from);
14
15
  try {
@@ -45,6 +46,9 @@ export async function syncChanges(mesh, view, from) {
45
46
  case '@qvac/knowledge-artifacts':
46
47
  await mesh.files.syncArtifact(change.value);
47
48
  break;
49
+ case '@qvac/joined-meshes':
50
+ roomsChanged = true;
51
+ break;
48
52
  }
49
53
  }
50
54
  indexingDirty = await files.ids();
@@ -60,4 +64,6 @@ export async function syncChanges(mesh, view, from) {
60
64
  await mesh.refreshMembership();
61
65
  if (agentsDirty)
62
66
  mesh.emit('agents-dirty');
67
+ if (roomsChanged)
68
+ mesh.emit('rooms-dirty');
63
69
  }
@@ -4,7 +4,7 @@ import type { BootstrapNode } from 'hyperswarm';
4
4
  import ReadyGuard from 'ready-guard';
5
5
  import ReadyResource from 'ready-resource';
6
6
  import type { Logger } from '../index.ts';
7
- import type { AssistantCompactChatResponse, AssistantCopySkillResponse, AssistantDeleteModelRequest, AssistantDeleteModelResponse, AssistantDeleteSkillResponse, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantManagedSkillsResponse, AssistantModelCatalogRevision, AssistantModelInfoList, AssistantOkResponse, AssistantSkillCatalogResponse, AssistantSkillFileResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantTranscribeRequest, AssistantTranscribeResponse } from '../spec/index.d.ts';
7
+ import type { AssistantCompactChatResponse, AssistantCopySkillResponse, AssistantDeleteModelRequest, AssistantDeleteModelResponse, AssistantDeleteSkillResponse, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantManagedSkillsResponse, AssistantMeshList, AssistantModelCatalogRevision, AssistantModelInfoList, AssistantOkResponse, AssistantSkillCatalogResponse, AssistantSkillFileResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantTranscribeRequest, AssistantTranscribeResponse } from '../spec/index.d.ts';
8
8
  import { type BlindPeeringOpts } from './core/blind-peers.ts';
9
9
  import { type IndexingEmbedder, type RagExtractors, type VectorIndex } from './core/files/index.ts';
10
10
  import { type DriveHost } from './core/fs-drives.ts';
@@ -62,6 +62,18 @@ export interface CoreOptions {
62
62
  readonly resume: () => Promise<void>;
63
63
  };
64
64
  }
65
+ export declare const MEMBER_INVITE_HOME_REFUSED = "An account mesh cannot be invited into";
66
+ export declare const DEVICE_INVITE_ROOM_REFUSED = "Only an account mesh can take a device invite";
67
+ export declare const INVITE_ACCOUNT_UNREADABLE = "This device cannot reach its account to check";
68
+ export declare const ROOM_HELD_BY_SIBLING = "Another of your devices holds this room: bring that device online, or invite from it instead";
69
+ export interface SharedRoom {
70
+ readonly meshId: string;
71
+ readonly notice?: string;
72
+ }
73
+ export interface MeshInviteOptions {
74
+ memberInvite?: boolean;
75
+ meshId?: string;
76
+ }
65
77
  export interface SkillManagementHooks {
66
78
  listManagedSkills(): Promise<AssistantManagedSkillsResponse>;
67
79
  readSkillFile(name: string): Promise<AssistantSkillFileResponse>;
@@ -75,6 +87,7 @@ export declare class Core extends ReadyResource {
75
87
  rootCorestore: Corestore;
76
88
  storage: CorestoreStorage;
77
89
  local: ReturnType<typeof openLocalStore>;
90
+ private readonly _deviceInvites;
78
91
  state: LocalQvacState;
79
92
  private readonly _transport;
80
93
  private readonly _apiLifecycle;
@@ -109,42 +122,42 @@ export declare class Core extends ReadyResource {
109
122
  private _indexedEmbedder;
110
123
  private readonly _indexingLock;
111
124
  private readonly _meshTransitionLock;
112
- private _processingFiles;
125
+ private readonly _opening;
113
126
  private _skills;
114
127
  private _skillCatalog;
115
128
  private _skillManagement;
116
129
  private readonly _catalogHooks;
117
130
  private _tools;
118
131
  private readonly _hostsModelSource;
119
- private _vectorIndex;
132
+ private _spareVectorIndex;
120
133
  private readonly _closeSignal;
121
134
  private _signalClose;
122
135
  private readonly _closeListeners;
123
136
  private _closeSignaled;
124
- private _mesh;
137
+ private readonly _meshes;
138
+ private readonly _blobCoreMeshes;
139
+ private _activeMeshKey;
125
140
  private readonly _offlineBoot;
126
141
  readonly onlineBoot: ReadyGuard;
127
142
  private _candidateMesh;
128
143
  private _cancelCandidateJoin;
129
144
  private _joinCancellation;
130
- private _meshSecretSeed;
131
145
  private readonly _rpcs;
132
146
  private _stream;
133
147
  private _api;
134
148
  private readonly _clients;
135
149
  private _deviceKeyPair;
136
- private readonly _memberLock;
137
150
  private _identityPhrase;
138
151
  private _identityPublicKey;
139
152
  private _swarm;
140
153
  private _departures;
141
154
  private _fsDrives;
142
155
  private _blobServer;
143
- private readonly _attachmentUrl;
144
156
  private readonly _wakeup;
157
+ private readonly _meshSeedHandoff;
158
+ private readonly _following;
145
159
  private readonly _secretHandoff;
146
160
  private readonly _skillOverlayHandoff;
147
- private _hostedAgents;
148
161
  private _minting;
149
162
  private _leaving;
150
163
  private _kicked;
@@ -153,9 +166,6 @@ export declare class Core extends ReadyResource {
153
166
  private readonly _statusListeners;
154
167
  private readonly _diagnosticsProviders;
155
168
  private _systemInfo;
156
- private readonly _onMeshWritable;
157
- private readonly _onMeshDead;
158
- private readonly _onMeshStalled;
159
169
  private _statusError;
160
170
  private _upgradeRequired;
161
171
  constructor(transport: Transport, { storagePath, logger, spec, bootstrapNodes, device, app, minSupportedVersion, otaConfigCore, blindPeerKeys, blindPeeringOpts, meshSeed, meshKey, additionalNodes, listModels, deleteModel, clearKvCache, deleteChatKvCache, compactChat, modelCatalogWatch, retryModelDownload, transcribe, speak, speakStream, embedder, extractors, skills, skillCatalog, tools, hostsModelSource, vectorIndex, apiLifecycle }: CoreOptions);
@@ -193,8 +203,11 @@ export declare class Core extends ReadyResource {
193
203
  private _openSwarm;
194
204
  private _resolveBlindPeerKeys;
195
205
  private _startMesh;
206
+ private _switchToMesh;
196
207
  private _openMesh;
208
+ private _openMeshSession;
197
209
  private _mintBirthMember;
210
+ private _joinBirthMember;
198
211
  private _holdIdentityPhrase;
199
212
  private _pushIdentityPhrase;
200
213
  private _offerIdentityPhrase;
@@ -202,12 +215,21 @@ export declare class Core extends ReadyResource {
202
215
  private _advertiseDeviceProfile;
203
216
  private _advertiseAppVersion;
204
217
  private _settleMembership;
218
+ private _claimOwnMembership;
219
+ private _knownMember;
205
220
  private _migrationContext;
206
- private _recordMembership;
221
+ private _recordMemberProof;
207
222
  private _ensureNotRevoked;
208
223
  private _retireMesh;
224
+ private _retirePooledMesh;
225
+ private _stopMeshServices;
226
+ private _stopEntryIndexing;
227
+ private _releaseVectorIndex;
209
228
  private _withdrawFromMesh;
210
229
  private _onKicked;
230
+ private _replaceRevokedActiveMesh;
231
+ private _departRevokedMesh;
232
+ private _archiveMembership;
211
233
  private _requestFreshMesh;
212
234
  private _onClose;
213
235
  private _waitForMeshChange;
@@ -217,10 +239,33 @@ export declare class Core extends ReadyResource {
217
239
  private _joinMesh;
218
240
  private _runJoinMesh;
219
241
  private _joinParkedMesh;
242
+ private _departOldAccount;
243
+ private _departIfPooled;
244
+ private _seedMemberDefaults;
245
+ private _hasOwnDefaultAgent;
246
+ private _recordJoinedRoom;
247
+ private _registerRoom;
248
+ private _releaseJoinedRoom;
249
+ private _accountMesh;
220
250
  private _openCandidateMesh;
221
251
  private _waitForCandidateWritable;
252
+ private _onMeshWritable;
253
+ private _onMeshDead;
254
+ private _onMeshStalled;
255
+ private _wireMesh;
256
+ private _handOffActive;
222
257
  private _activateMesh;
223
258
  private _currentMesh;
259
+ private _poolKey;
260
+ private _poolEntry;
261
+ private _meshFor;
262
+ private _activeEntry;
263
+ private _meshForBlobCore;
264
+ private _linkAttachment;
265
+ private _isPooled;
266
+ private _isActive;
267
+ private _unpoolMesh;
268
+ private _unwireMesh;
224
269
  private _awaitMesh;
225
270
  private _startMeshServices;
226
271
  private _stopHostedAgents;
@@ -228,14 +273,45 @@ export declare class Core extends ReadyResource {
228
273
  private _departureHasAudience;
229
274
  private _announceDeparture;
230
275
  leaveMesh(): Promise<void>;
276
+ private _isHomeMesh;
277
+ private _homeMeshKey;
278
+ private _writableFallback;
279
+ listMeshes(): Promise<AssistantMeshList>;
280
+ private _meshLabels;
281
+ private _isOwnRoomIn;
282
+ setMeshLabel(meshId: string, label: string): Promise<void>;
283
+ createRoom({ shared }?: {
284
+ shared?: boolean;
285
+ }): Promise<string>;
286
+ sharedRoom(): Promise<SharedRoom>;
287
+ private _occupancyNotice;
288
+ private _resolveSharedRoom;
289
+ private _unmarkSharedRoom;
290
+ private _mintRoom;
291
+ private _discardRoom;
292
+ openMesh(meshId: string): Promise<void>;
293
+ selectMesh(meshId: string): Promise<void>;
294
+ closeMesh(meshId: string): Promise<void>;
295
+ private _openPooledMesh;
296
+ private _openRecordedMesh;
297
+ private _meshEntry;
298
+ private _meshEntryState;
299
+ private _meshKeyOf;
231
300
  removeDeviceWriter(writerKey: Buffer, deviceId: Buffer): Promise<void>;
232
301
  renameLocalDevice(name: string): Promise<void>;
233
302
  saveDeviceProfileLocal(capabilityProfile: DeviceMetadata['capabilityProfile'], recommendedModelName: string, platform?: string): Promise<void>;
234
303
  waitForWritable(): Promise<void>;
235
- getMeshInvite(): Promise<MeshInvite | null>;
304
+ private _assertRoomIsHere;
305
+ getMeshInvite(opts?: MeshInviteOptions): Promise<MeshInvite | null>;
236
306
  private _closeSwarm;
237
307
  pushSkillSecret(request: SecretRequest): Promise<void>;
238
308
  private _storeHandedOffSecret;
309
+ private _followJoinedRooms;
310
+ private _openFollowedRoom;
311
+ private _requestRoomSeed;
312
+ private _serveMeshSeed;
313
+ private _isJoinedRoomKey;
314
+ private _isOwnMemberDevice;
239
315
  private _skillOverlayOp;
240
316
  private _resolveSkillOverlayHost;
241
317
  private _serveSkillOverlayOp;
@@ -277,6 +353,8 @@ export declare class Core extends ReadyResource {
277
353
  registerEmbedder(embedder: IndexingEmbedder, extractors?: RagExtractors): () => Promise<void>;
278
354
  private _reconcileIndexing;
279
355
  private _startIndexing;
356
+ private _startEntryIndexing;
357
+ private _takeVectorIndex;
280
358
  private _stopIndexing;
281
359
  registerTranscribe(hook: (request: AssistantTranscribeRequest) => Promise<AssistantTranscribeResponse>): () => void;
282
360
  registerSpeak(hook: (request: AssistantSpeakRequest) => Promise<AssistantSpeakResponse>): () => void;