@qvac/core 1.0.0-rc.12 → 1.0.0-rc.13

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 (63) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist-lib/lib/assistant.js +2 -1
  3. package/dist-lib/lib/core/archived-mesh.js +7 -3
  4. package/dist-lib/lib/core/chat-copy.d.ts +18 -3
  5. package/dist-lib/lib/core/chat-copy.js +73 -23
  6. package/dist-lib/lib/core/chat-group.js +14 -9
  7. package/dist-lib/lib/core/chat-move.d.ts +9 -0
  8. package/dist-lib/lib/core/chat-move.js +94 -3
  9. package/dist-lib/lib/core/chat.js +21 -8
  10. package/dist-lib/lib/core/collections.d.ts +1 -0
  11. package/dist-lib/lib/core/collections.js +1 -0
  12. package/dist-lib/lib/core/contract/activity.js +2 -2
  13. package/dist-lib/lib/core/contract/chat-group.d.ts +1 -0
  14. package/dist-lib/lib/core/contract/chat-group.js +21 -1
  15. package/dist-lib/lib/core/contract/chat.d.ts +9 -0
  16. package/dist-lib/lib/core/contract/chat.js +127 -5
  17. package/dist-lib/lib/core/contract/chunks.d.ts +1 -0
  18. package/dist-lib/lib/core/contract/chunks.js +37 -6
  19. package/dist-lib/lib/core/contract/features.d.ts +21 -0
  20. package/dist-lib/lib/core/contract/features.js +22 -0
  21. package/dist-lib/lib/core/contract/indexing.js +4 -2
  22. package/dist-lib/lib/core/contract/knowledge.js +5 -4
  23. package/dist-lib/lib/core/contract/members.js +2 -2
  24. package/dist-lib/lib/core/contract/projects.d.ts +5 -0
  25. package/dist-lib/lib/core/contract/projects.js +12 -4
  26. package/dist-lib/lib/core/contract/roles.js +30 -4
  27. package/dist-lib/lib/core/contract/run-requests.js +2 -2
  28. package/dist-lib/lib/core/contract/seed-defaults.js +2 -2
  29. package/dist-lib/lib/core/contract/tool-configs.js +3 -2
  30. package/dist-lib/lib/core/contract/workspace.d.ts +2 -0
  31. package/dist-lib/lib/core/contract/workspace.js +40 -7
  32. package/dist-lib/lib/core/contract/writers.js +2 -2
  33. package/dist-lib/lib/core/files/attachments.js +4 -1
  34. package/dist-lib/lib/core/local/index.d.ts +6 -2
  35. package/dist-lib/lib/core/local/index.js +12 -3
  36. package/dist-lib/lib/core/mesh.d.ts +5 -0
  37. package/dist-lib/lib/core/mesh.js +3 -0
  38. package/dist-lib/lib/core/migrations/workspace-from-0-21/index.d.ts +85 -0
  39. package/dist-lib/lib/core/migrations/workspace-from-0-21/index.js +690 -0
  40. package/dist-lib/lib/core/project-keys.d.ts +6 -0
  41. package/dist-lib/lib/core/project-keys.js +11 -0
  42. package/dist-lib/lib/core/public-mesh.d.ts +2 -0
  43. package/dist-lib/lib/core/public-mesh.js +5 -0
  44. package/dist-lib/lib/core/sync/changed.d.ts +4 -2
  45. package/dist-lib/lib/core/sync/changed.js +1 -1
  46. package/dist-lib/lib/core/sync/index.js +27 -2
  47. package/dist-lib/lib/core/workspace-upgrade.d.ts +6 -0
  48. package/dist-lib/lib/core/workspace-upgrade.js +26 -16
  49. package/dist-lib/lib/core.d.ts +4 -32
  50. package/dist-lib/lib/core.js +117 -469
  51. package/dist-lib/lib/run-transcript.d.ts +2 -1
  52. package/dist-lib/lib/run-transcript.js +11 -5
  53. package/dist-lib/schema/qvac.js +26 -1
  54. package/dist-lib/spec/mesh/hyperdb/db.json +15 -0
  55. package/dist-lib/spec/mesh/hyperdb/index.js +70 -1
  56. package/dist-lib/spec/mesh/hyperdb/messages.js +806 -438
  57. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +18 -0
  58. package/dist-lib/spec/mesh/hyperdispatch/index.js +52 -1
  59. package/dist-lib/spec/mesh/hyperdispatch/messages.js +303 -3
  60. package/dist-lib/spec/mesh/hyperschema/index.js +303 -3
  61. package/dist-lib/spec/mesh/hyperschema/schema.json +146 -0
  62. package/dist-lib/spec/mesh/hyperschema/types.d.ts +39 -0
  63. package/package.json +6 -4
@@ -14,7 +14,7 @@ import { dropHostRows, hostedDevice, releaseHostedDevice } from './agent-join.js
14
14
  import { actsFor, dropRole, kicksAdminsLastDevice, leavesNoAdmin, uncountMember } from './workspace.js';
15
15
  import { verifyDeviceProof } from '../identity.js';
16
16
  import { sealed } from './seal.js';
17
- import { WORKSPACES_RULES, rulesVersion } from './mesh-rules.js';
17
+ import { FEATURES, isFeatureSupported } from './features.js';
18
18
  import b4a from 'b4a';
19
19
  import { DEVICES, MEMBERS, MESH_INVITE_GRANTS, PROJECT_MEMBERS } from '../collections.js';
20
20
  async function boundToAnother(tx, writerKey, id) {
@@ -191,7 +191,7 @@ async function ownLeave({ writerKey, deviceId, revokedAt }, { tx, node }) {
191
191
  if (!b4a.equals(node.key, writerKey) || !deviceId) {
192
192
  return false;
193
193
  }
194
- if ((await rulesVersion(tx)) < WORKSPACES_RULES) {
194
+ if (!(await isFeatureSupported(tx, FEATURES.OWN_LEAVE_HOLDS))) {
195
195
  return false;
196
196
  }
197
197
  const device = await tx.get(DEVICES, { id: deviceId });
@@ -1,5 +1,6 @@
1
1
  import { CoreError } from '../../errors.js';
2
2
  import { linkAttachment } from '../attachment-link.js';
3
+ import { mayEditChunk } from '../contract/chunks.js';
3
4
  import { getChunk, readChunk, updateChunk } from '../chunk.js';
4
5
  import { uploadFile } from './upload.js';
5
6
  import b4a from 'b4a';
@@ -49,7 +50,9 @@ export function attachmentFiles(mesh, { maxBytes = MAX_ATTACHMENT_BYTES, deviceI
49
50
  if (chunk.type !== 'attachment' || !chunk.attachment) {
50
51
  throw new CoreError('NOT_AN_ATTACHMENT', [chunkId]);
51
52
  }
52
- if (deviceId && !b4a.equals(chunk.originDeviceId, deviceId)) {
53
+ if (deviceId &&
54
+ !b4a.equals(chunk.originDeviceId, deviceId) &&
55
+ !(await mayEditChunk(mesh.view, chunk, mesh.localWriterKey))) {
53
56
  throw new CoreError('ATTACHMENT_DELETE_NOT_ORIGIN');
54
57
  }
55
58
  const attachment = chunk.attachment;
@@ -40,7 +40,7 @@ export declare const MESH_LOCAL_COLLECTIONS: readonly [{
40
40
  readonly collection: "@local/run-log-steps";
41
41
  readonly field: 'meshKey';
42
42
  }];
43
- export declare const MESH_CONFIG_FAMILIES: readonly ['workspace-upgrade', 'workspace-agents'];
43
+ export declare const MESH_CONFIG_FAMILIES: readonly ['workspace-upgrade', 'workspace-agents', 'workspace-edits', 'copied'];
44
44
  export interface ResolvedSession {
45
45
  readonly seed: Buffer;
46
46
  readonly baseKey: Buffer | undefined;
@@ -114,6 +114,9 @@ export interface DropMeshOptions {
114
114
  export interface RecordDepartureOptions {
115
115
  readonly creator: boolean;
116
116
  }
117
+ interface ArchiveMeshOptions {
118
+ readonly homeTo?: Buffer | null;
119
+ }
117
120
  export interface AdoptAccountMeshOptions {
118
121
  readonly account?: Buffer | null;
119
122
  readonly keepName?: boolean;
@@ -167,6 +170,7 @@ declare class LocalStore {
167
170
  readAccountRecovery(meshKey: Buffer): Promise<LocalAccountRecovery | null>;
168
171
  readChatMove(meshKey: Buffer, chatId: string): Promise<LocalChatMove | null>;
169
172
  listChatMoves(): Promise<LocalChatMove[]>;
173
+ listChatMovesFrom(meshKey: Buffer): Promise<LocalChatMove[]>;
170
174
  readMeshUpdate(meshKey: Buffer): Promise<LocalMeshUpdate | null>;
171
175
  updateMeshUpdate(meshKey: Buffer, change: (row: LocalMeshUpdate | null) => LocalMeshUpdate | null): Promise<void>;
172
176
  meshNames(): Promise<LocalMeshName[]>;
@@ -188,7 +192,7 @@ declare class LocalStore {
188
192
  departures(): Promise<LocalMeshDeparture[]>;
189
193
  departureRole(departure: LocalMeshDeparture): Promise<MeshRole>;
190
194
  deleteDeparture(key: Buffer): Promise<void>;
191
- archiveMesh(key: Buffer): Promise<void>;
195
+ archiveMesh(key: Buffer, { homeTo }?: ArchiveMeshOptions): Promise<void>;
192
196
  markRetired(keys: Buffer[], accountKey: Buffer): Promise<void>;
193
197
  unretire(accountKey: Buffer): Promise<Buffer[]>;
194
198
  markKicked(key: Buffer): Promise<void>;
@@ -24,7 +24,12 @@ export const MESH_LOCAL_COLLECTIONS = [
24
24
  { collection: LOCAL_RUN_LOGS, field: 'meshKey' },
25
25
  { collection: LOCAL_RUN_LOG_STEPS, field: 'meshKey' }
26
26
  ];
27
- export const MESH_CONFIG_FAMILIES = ['workspace-upgrade', 'workspace-agents'];
27
+ export const MESH_CONFIG_FAMILIES = [
28
+ 'workspace-upgrade',
29
+ 'workspace-agents',
30
+ 'workspace-edits',
31
+ 'copied'
32
+ ];
28
33
  const IDENTITY_ID = 'identity';
29
34
  const MEMBERSHIP_ID = 'membership';
30
35
  const APP_CONFIG_ID = 'default';
@@ -418,6 +423,10 @@ class LocalStore {
418
423
  listChatMoves() {
419
424
  return this._db.find(LOCAL_CHAT_MOVES).toArray();
420
425
  }
426
+ listChatMovesFrom(meshKey) {
427
+ const range = { gte: { meshKey }, lte: { meshKey } };
428
+ return this._db.find(LOCAL_CHAT_MOVES, range).toArray();
429
+ }
421
430
  readMeshUpdate(meshKey) {
422
431
  return this._db.get(LOCAL_MESH_UPDATES, { meshKey });
423
432
  }
@@ -653,7 +662,7 @@ class LocalStore {
653
662
  await tx.flush();
654
663
  });
655
664
  }
656
- archiveMesh(key) {
665
+ archiveMesh(key, { homeTo = null } = {}) {
657
666
  return this._locked(async () => {
658
667
  const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
659
668
  const { cleared, home } = await this._pointersAt(key);
@@ -666,7 +675,7 @@ class LocalStore {
666
675
  });
667
676
  }
668
677
  for (const pointer of cleared) {
669
- await tx.insert(LOCAL_ACTIVE_MESH, pointer);
678
+ await tx.insert(LOCAL_ACTIVE_MESH, { ...pointer, homeMeshKey: homeTo });
670
679
  }
671
680
  await this._dropChatOrder(tx, key);
672
681
  await this._dropRows(tx, key, { collection: LOCAL_FILES, field: 'meshKey' });
@@ -45,12 +45,16 @@ export interface MeshOptions {
45
45
  wakeup?: Wakeup;
46
46
  attachmentUrl?: AttachmentUrl | null;
47
47
  fileIndex?: MeshFileIndex | null;
48
+ history?: MeshHistory | null;
48
49
  pendingUpdates?: PendingUpdates | null;
49
50
  sidebarChats?: SidebarChats | null;
50
51
  onerror?: ErrorSink;
51
52
  slowWriteMs?: number;
52
53
  slowDrainMs?: number;
53
54
  }
55
+ export interface MeshHistory {
56
+ edited(chatIds: ReadonlySet<string> | null): Promise<void>;
57
+ }
54
58
  export type SidebarChats = (limit: number) => Promise<ReadonlyArray<{
55
59
  readonly chatId: string;
56
60
  }>>;
@@ -130,6 +134,7 @@ export declare class Mesh extends ReadyResource {
130
134
  private readonly _wakeup;
131
135
  readonly attachmentUrl: AttachmentUrl | null;
132
136
  readonly fileIndex: MeshFileIndex | null;
137
+ readonly history: MeshHistory | null;
133
138
  private readonly _scope;
134
139
  readonly router: Router;
135
140
  private readonly _keyPair;
@@ -104,6 +104,7 @@ export class Mesh extends ReadyResource {
104
104
  _wakeup;
105
105
  attachmentUrl;
106
106
  fileIndex;
107
+ history;
107
108
  _scope;
108
109
  router;
109
110
  _keyPair;
@@ -304,6 +305,7 @@ export class Mesh extends ReadyResource {
304
305
  this._wakeup = opts.wakeup;
305
306
  this.attachmentUrl = opts.attachmentUrl ?? null;
306
307
  this.fileIndex = opts.fileIndex ?? null;
308
+ this.history = opts.history ?? null;
307
309
  this._sidebarChats = opts.sidebarChats ?? null;
308
310
  this._updates = new ViewUpdates((update) => this._syncUpdate(update), {
309
311
  pending: opts.pendingUpdates ?? memoryPending(),
@@ -1097,6 +1099,7 @@ export class Mesh extends ReadyResource {
1097
1099
  reached = await syncChanges(this, this.autobee.view, from);
1098
1100
  }
1099
1101
  else {
1102
+ await this.history?.edited(null);
1100
1103
  this._arrive();
1101
1104
  }
1102
1105
  if (this._admitted && !this.autobee.writable) {
@@ -0,0 +1,85 @@
1
+ import type { KeyPair } from 'hyperswarm';
2
+ import type { Logger } from '../../../../index.ts';
3
+ import type { QvacProject } from '../../../../spec/mesh/hyperschema/types.d.ts';
4
+ import type { MeshRole } from '../../contract/roles.ts';
5
+ import { openLocalStore } from '../../local/index.ts';
6
+ import type { Mesh, MeshHistory, ProjectIdentity } from '../../mesh.ts';
7
+ import { type PublicRecord } from '../../public-mesh.ts';
8
+ import type { AgentPicks } from '../../shared-agents.ts';
9
+ export interface UpgradeHost {
10
+ readonly closing: Promise<void> | null;
11
+ readonly local: ReturnType<typeof openLocalStore>;
12
+ readonly log: Logger | null;
13
+ readonly ownWorkspaceId: string | null;
14
+ accountMesh(): Mesh | null;
15
+ agentPicks(): AgentPicks;
16
+ followProjects(workspace: Mesh): Promise<void>;
17
+ following(meshId: string): Promise<void> | undefined;
18
+ heldMesh(key: Buffer): Promise<Mesh | null>;
19
+ isAccount(mesh: Mesh): boolean;
20
+ isPooled(mesh: Mesh): boolean;
21
+ listProject(workspace: Mesh, project: Pick<Mesh, 'key' | 'seed'>, listing: Omit<QvacProject, 'id'>): Promise<void>;
22
+ meshIdOf(mesh: Mesh): string;
23
+ notifyStatus(): void;
24
+ openNewProject(workspace: Mesh, project: ProjectIdentity): Promise<Mesh>;
25
+ openPooledMesh(meshId: string): Promise<Mesh>;
26
+ pooled(meshId: string | null): Mesh | null;
27
+ publicMesh(workspaceId: string): Mesh | null;
28
+ publicRecord(account: Mesh, workspaceKey: Buffer): Promise<PublicRecord | null>;
29
+ publicWriter(mesh: Mesh): boolean;
30
+ purgeProject(key: Buffer): Promise<void>;
31
+ reopenInRole(mesh: Mesh, role: MeshRole): Promise<void>;
32
+ requireDeviceKeyPair(): KeyPair;
33
+ savePublicRecord(account: Mesh, workspaceKey: Buffer, record: PublicRecord): Promise<void>;
34
+ storedAccountKey(): Promise<Buffer | undefined>;
35
+ writableAccount(): Promise<Mesh | null>;
36
+ }
37
+ export declare class WorkspaceUpgrade {
38
+ private readonly _host;
39
+ private readonly _upgrading;
40
+ private readonly _groupPasses;
41
+ private readonly _groupPassesDue;
42
+ private _publicMigration;
43
+ private _copyAgain;
44
+ private _accountCopied;
45
+ constructor(host: UpgradeHost);
46
+ get accountCopy(): Promise<void> | null;
47
+ get accountUnread(): boolean;
48
+ followShared(mesh: Mesh): Promise<void>;
49
+ follow(workspace: Mesh): void;
50
+ private _passGroups;
51
+ private _rehome;
52
+ private _rehomeInto;
53
+ private _carryHome;
54
+ private _removeCarried;
55
+ private _groupBuckets;
56
+ private _markFoldDue;
57
+ private _passAgents;
58
+ private _heldProjects;
59
+ private _groupRecord;
60
+ private _scanBuckets;
61
+ private _passGroup;
62
+ private _followPours;
63
+ private _foundGroupProject;
64
+ private _mergeGroupInto;
65
+ private _winnerOf;
66
+ private _copyGroup;
67
+ private _copyBaseline;
68
+ private _addWorkspaceMembers;
69
+ private _settleListed;
70
+ private _listNewMembers;
71
+ private _listWorkspaceMembers;
72
+ boot(): Promise<void>;
73
+ private _markUpgradeChecked;
74
+ private _upgradable;
75
+ private _markJoinedWorkspace;
76
+ copyAccount(account: Mesh): void;
77
+ private _copyTargets;
78
+ private _copyAccountInto;
79
+ refill(into: Mesh): Promise<void>;
80
+ private _recordCopied;
81
+ private _markCopied;
82
+ history(mesh: () => Mesh): MeshHistory;
83
+ private _noteEdits;
84
+ private _noteLateWrites;
85
+ }