gnosys 5.2.24 → 5.3.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.
- package/README.md +43 -5
- package/dist/cli.js +303 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/db.d.ts +21 -0
- package/dist/lib/db.d.ts.map +1 -1
- package/dist/lib/db.js +61 -0
- package/dist/lib/db.js.map +1 -1
- package/dist/lib/remote.d.ts +112 -0
- package/dist/lib/remote.d.ts.map +1 -0
- package/dist/lib/remote.js +511 -0
- package/dist/lib/remote.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gnosys Remote Sync — multi-machine database synchronization
|
|
3
|
+
*
|
|
4
|
+
* Hybrid sync strategy:
|
|
5
|
+
* - Local DB acts as a fast working cache
|
|
6
|
+
* - Remote DB (typically NAS) is the canonical source of truth
|
|
7
|
+
* - Reads always hit local for speed
|
|
8
|
+
* - Writes go to local + queued for remote push
|
|
9
|
+
* - Conflict detection via per-memory `modified` timestamps
|
|
10
|
+
* - Skip-and-flag for auto sync; AI-mediated resolution for conflicts
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, statSync, mkdirSync, writeFileSync, unlinkSync } from "fs";
|
|
13
|
+
import * as path from "path";
|
|
14
|
+
import { GnosysDB } from "./db.js";
|
|
15
|
+
// ─── Validation ─────────────────────────────────────────────────────────
|
|
16
|
+
/**
|
|
17
|
+
* Validate that a directory is suitable for hosting the remote gnosys.db.
|
|
18
|
+
* Tests writability, SQLite locking, and latency.
|
|
19
|
+
*/
|
|
20
|
+
export async function validateLocation(remotePath) {
|
|
21
|
+
const result = {
|
|
22
|
+
ok: false,
|
|
23
|
+
checks: {
|
|
24
|
+
pathExists: false,
|
|
25
|
+
writable: false,
|
|
26
|
+
sqliteCompatible: false,
|
|
27
|
+
latencyMs: null,
|
|
28
|
+
existingDb: { found: false },
|
|
29
|
+
},
|
|
30
|
+
warnings: [],
|
|
31
|
+
errors: [],
|
|
32
|
+
};
|
|
33
|
+
// 1. Path exists?
|
|
34
|
+
try {
|
|
35
|
+
const stat = statSync(remotePath);
|
|
36
|
+
if (!stat.isDirectory()) {
|
|
37
|
+
result.errors.push(`Path exists but is not a directory: ${remotePath}`);
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
result.checks.pathExists = true;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Try to create it
|
|
44
|
+
try {
|
|
45
|
+
mkdirSync(remotePath, { recursive: true });
|
|
46
|
+
result.checks.pathExists = true;
|
|
47
|
+
result.warnings.push(`Created directory: ${remotePath}`);
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
result.errors.push(`Cannot access or create path: ${remotePath} (${err.message})`);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// 2. Writable?
|
|
55
|
+
const testFile = path.join(remotePath, `.gnosys-write-test-${Date.now()}`);
|
|
56
|
+
try {
|
|
57
|
+
writeFileSync(testFile, "test");
|
|
58
|
+
unlinkSync(testFile);
|
|
59
|
+
result.checks.writable = true;
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
result.errors.push(`Cannot write to path: ${err.message}`);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
// 3. SQLite compatible?
|
|
66
|
+
const testDbPath = path.join(remotePath, ".gnosys-sqlite-test");
|
|
67
|
+
try {
|
|
68
|
+
const start = Date.now();
|
|
69
|
+
const testDb = new GnosysDB(remotePath);
|
|
70
|
+
if (!testDb.isAvailable()) {
|
|
71
|
+
result.errors.push("better-sqlite3 not available");
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
// Simple read/write probe
|
|
75
|
+
testDb.setMeta("__sqlite_test__", "ok");
|
|
76
|
+
const val = testDb.getMeta("__sqlite_test__");
|
|
77
|
+
testDb.close();
|
|
78
|
+
if (val !== "ok") {
|
|
79
|
+
result.errors.push("SQLite read/write probe failed — locking may be unreliable on this filesystem");
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
result.checks.sqliteCompatible = true;
|
|
83
|
+
result.checks.latencyMs = Date.now() - start;
|
|
84
|
+
if (result.checks.latencyMs > 500) {
|
|
85
|
+
result.warnings.push(`High latency detected: ${result.checks.latencyMs}ms (consider local DB if remote feels slow)`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
result.errors.push(`SQLite test failed: ${err.message}`);
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
try {
|
|
94
|
+
unlinkSync(testDbPath);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// ignore
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// 4. Existing DB?
|
|
101
|
+
const dbFile = path.join(remotePath, "gnosys.db");
|
|
102
|
+
if (existsSync(dbFile)) {
|
|
103
|
+
try {
|
|
104
|
+
const db = new GnosysDB(remotePath);
|
|
105
|
+
const counts = db.getMemoryCount();
|
|
106
|
+
const stat = statSync(dbFile);
|
|
107
|
+
db.close();
|
|
108
|
+
result.checks.existingDb = {
|
|
109
|
+
found: true,
|
|
110
|
+
memoryCount: counts.total,
|
|
111
|
+
lastModified: stat.mtime.toISOString(),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
result.warnings.push("Found gnosys.db at path but couldn't read it");
|
|
116
|
+
result.checks.existingDb = { found: true };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
result.ok = result.checks.pathExists && result.checks.writable && result.checks.sqliteCompatible;
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
// ─── Sync engine ────────────────────────────────────────────────────────
|
|
123
|
+
const META_LAST_SYNC = "remote_last_synced_at";
|
|
124
|
+
const META_MACHINE_ID = "machine_id";
|
|
125
|
+
export class RemoteSync {
|
|
126
|
+
localDb;
|
|
127
|
+
remotePath;
|
|
128
|
+
remoteDb = null;
|
|
129
|
+
constructor(localDb, remotePath) {
|
|
130
|
+
this.localDb = localDb;
|
|
131
|
+
this.remotePath = remotePath;
|
|
132
|
+
}
|
|
133
|
+
/** Check if remote is reachable. Lazy-opens the remote DB. */
|
|
134
|
+
getRemoteDb() {
|
|
135
|
+
if (this.remoteDb)
|
|
136
|
+
return this.remoteDb;
|
|
137
|
+
try {
|
|
138
|
+
// Check path is reachable first (mounted, accessible)
|
|
139
|
+
if (!existsSync(this.remotePath))
|
|
140
|
+
return null;
|
|
141
|
+
const db = new GnosysDB(this.remotePath);
|
|
142
|
+
if (!db.isAvailable()) {
|
|
143
|
+
db.close();
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
this.remoteDb = db;
|
|
147
|
+
return db;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
closeRemote() {
|
|
154
|
+
this.remoteDb?.close();
|
|
155
|
+
this.remoteDb = null;
|
|
156
|
+
}
|
|
157
|
+
/** Get current sync status without modifying anything */
|
|
158
|
+
async getStatus() {
|
|
159
|
+
const remoteDb = this.getRemoteDb();
|
|
160
|
+
const reachable = remoteDb !== null;
|
|
161
|
+
const lastSync = this.localDb.getMeta(META_LAST_SYNC);
|
|
162
|
+
const queued = this.localDb.getPendingSync();
|
|
163
|
+
const conflictRows = this.localDb.getUnresolvedConflicts();
|
|
164
|
+
const conflicts = conflictRows.map((c) => {
|
|
165
|
+
const local = this.localDb.getMemory(c.memory_id);
|
|
166
|
+
return {
|
|
167
|
+
memoryId: c.memory_id,
|
|
168
|
+
title: local?.title || c.memory_id,
|
|
169
|
+
localModified: c.local_modified,
|
|
170
|
+
remoteModified: c.remote_modified,
|
|
171
|
+
localSnapshot: c.local_snapshot || undefined,
|
|
172
|
+
remoteSnapshot: c.remote_snapshot || undefined,
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
let pendingPush = queued.length;
|
|
176
|
+
let pendingPull = 0;
|
|
177
|
+
if (reachable && remoteDb) {
|
|
178
|
+
// Count memories that would push/pull on next sync
|
|
179
|
+
const since = lastSync || "1970-01-01T00:00:00Z";
|
|
180
|
+
const localChanges = this.localDb
|
|
181
|
+
.getAllMemories()
|
|
182
|
+
.filter((m) => (m.modified || m.created) > since);
|
|
183
|
+
const remoteChanges = remoteDb
|
|
184
|
+
.getAllMemories()
|
|
185
|
+
.filter((m) => (m.modified || m.created) > since);
|
|
186
|
+
const remoteIds = new Set(remoteChanges.map((m) => m.id));
|
|
187
|
+
pendingPush = localChanges.filter((m) => {
|
|
188
|
+
const remote = remoteDb.getMemory(m.id);
|
|
189
|
+
if (!remote)
|
|
190
|
+
return true; // not on remote
|
|
191
|
+
return m.modified > remote.modified;
|
|
192
|
+
}).length;
|
|
193
|
+
pendingPull = remoteChanges.filter((m) => {
|
|
194
|
+
const local = this.localDb.getMemory(m.id);
|
|
195
|
+
if (!local)
|
|
196
|
+
return true;
|
|
197
|
+
return m.modified > local.modified;
|
|
198
|
+
}).length;
|
|
199
|
+
}
|
|
200
|
+
let message;
|
|
201
|
+
if (!reachable && this.remotePath) {
|
|
202
|
+
message = `Remote unreachable at ${this.remotePath}`;
|
|
203
|
+
}
|
|
204
|
+
else if (conflicts.length > 0) {
|
|
205
|
+
message = `${conflicts.length} unresolved conflict${conflicts.length !== 1 ? "s" : ""} need attention`;
|
|
206
|
+
}
|
|
207
|
+
else if (pendingPush > 0 || pendingPull > 0) {
|
|
208
|
+
const parts = [];
|
|
209
|
+
if (pendingPush > 0)
|
|
210
|
+
parts.push(`${pendingPush} to push`);
|
|
211
|
+
if (pendingPull > 0)
|
|
212
|
+
parts.push(`${pendingPull} to pull`);
|
|
213
|
+
message = `Sync needed: ${parts.join(", ")}`;
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
configured: true,
|
|
217
|
+
reachable,
|
|
218
|
+
remotePath: this.remotePath,
|
|
219
|
+
lastSync,
|
|
220
|
+
pendingPush,
|
|
221
|
+
pendingPull,
|
|
222
|
+
queuedWrites: queued.length,
|
|
223
|
+
conflicts,
|
|
224
|
+
message,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/** Push local changes to remote. Returns what was pushed/skipped. */
|
|
228
|
+
async push(options = {}) {
|
|
229
|
+
const strategy = options.strategy || "skip-and-flag";
|
|
230
|
+
const remoteDb = this.getRemoteDb();
|
|
231
|
+
if (!remoteDb) {
|
|
232
|
+
return { pushed: 0, pulled: 0, conflicts: [], errors: ["Remote not reachable"], skipped: 0 };
|
|
233
|
+
}
|
|
234
|
+
const lastSync = this.localDb.getMeta(META_LAST_SYNC) || "1970-01-01T00:00:00Z";
|
|
235
|
+
const localChanges = this.localDb
|
|
236
|
+
.getAllMemories()
|
|
237
|
+
.filter((m) => (m.modified || m.created) > lastSync);
|
|
238
|
+
const result = { pushed: 0, pulled: 0, conflicts: [], errors: [], skipped: 0 };
|
|
239
|
+
for (const local of localChanges) {
|
|
240
|
+
const remote = remoteDb.getMemory(local.id);
|
|
241
|
+
if (!remote) {
|
|
242
|
+
// Memory only exists locally — push
|
|
243
|
+
try {
|
|
244
|
+
remoteDb.insertMemory(local);
|
|
245
|
+
result.pushed++;
|
|
246
|
+
}
|
|
247
|
+
catch (err) {
|
|
248
|
+
result.errors.push(`Failed to push ${local.id}: ${err.message}`);
|
|
249
|
+
}
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
// Both exist — check if remote was also modified since last sync
|
|
253
|
+
const remoteChangedSinceSync = remote.modified > lastSync;
|
|
254
|
+
if (!remoteChangedSinceSync) {
|
|
255
|
+
// Remote unchanged — push local
|
|
256
|
+
if (local.modified > remote.modified) {
|
|
257
|
+
try {
|
|
258
|
+
remoteDb.insertMemory(local);
|
|
259
|
+
result.pushed++;
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
result.errors.push(`Failed to push ${local.id}: ${err.message}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
result.skipped++;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
// Both modified since last sync — true conflict
|
|
271
|
+
if (local.modified === remote.modified) {
|
|
272
|
+
// Same timestamp, assume same content
|
|
273
|
+
result.skipped++;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (strategy === "newer-wins") {
|
|
277
|
+
// Take whichever is newer
|
|
278
|
+
if (local.modified > remote.modified) {
|
|
279
|
+
try {
|
|
280
|
+
remoteDb.insertMemory(local);
|
|
281
|
+
result.pushed++;
|
|
282
|
+
}
|
|
283
|
+
catch (err) {
|
|
284
|
+
result.errors.push(`Failed to push ${local.id}: ${err.message}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
// Remote is newer — handled by pull, skip here
|
|
289
|
+
result.skipped++;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
// skip-and-flag — record conflict
|
|
294
|
+
this.localDb.recordConflict(local.id, local.modified, remote.modified, JSON.stringify({ title: local.title, content: local.content }), JSON.stringify({ title: remote.title, content: remote.content }));
|
|
295
|
+
result.conflicts.push({
|
|
296
|
+
memoryId: local.id,
|
|
297
|
+
title: local.title,
|
|
298
|
+
localModified: local.modified,
|
|
299
|
+
remoteModified: remote.modified,
|
|
300
|
+
});
|
|
301
|
+
result.skipped++;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Process pending sync queue (offline writes)
|
|
306
|
+
const queued = this.localDb.getPendingSync();
|
|
307
|
+
for (const item of queued) {
|
|
308
|
+
const local = this.localDb.getMemory(item.memory_id);
|
|
309
|
+
if (!local)
|
|
310
|
+
continue;
|
|
311
|
+
try {
|
|
312
|
+
remoteDb.insertMemory(local);
|
|
313
|
+
this.localDb.markPendingSyncComplete(item.id);
|
|
314
|
+
result.pushed++;
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
result.errors.push(`Failed to replay ${item.memory_id}: ${err.message}`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
/** Pull remote changes to local. Returns what was pulled/skipped. */
|
|
323
|
+
async pull(options = {}) {
|
|
324
|
+
const strategy = options.strategy || "skip-and-flag";
|
|
325
|
+
const remoteDb = this.getRemoteDb();
|
|
326
|
+
if (!remoteDb) {
|
|
327
|
+
return { pushed: 0, pulled: 0, conflicts: [], errors: ["Remote not reachable"], skipped: 0 };
|
|
328
|
+
}
|
|
329
|
+
const lastSync = this.localDb.getMeta(META_LAST_SYNC) || "1970-01-01T00:00:00Z";
|
|
330
|
+
const remoteChanges = remoteDb
|
|
331
|
+
.getAllMemories()
|
|
332
|
+
.filter((m) => (m.modified || m.created) > lastSync);
|
|
333
|
+
const result = { pushed: 0, pulled: 0, conflicts: [], errors: [], skipped: 0 };
|
|
334
|
+
for (const remote of remoteChanges) {
|
|
335
|
+
const local = this.localDb.getMemory(remote.id);
|
|
336
|
+
if (!local) {
|
|
337
|
+
// Memory only exists on remote — pull
|
|
338
|
+
try {
|
|
339
|
+
this.localDb.insertMemory(remote);
|
|
340
|
+
result.pulled++;
|
|
341
|
+
}
|
|
342
|
+
catch (err) {
|
|
343
|
+
result.errors.push(`Failed to pull ${remote.id}: ${err.message}`);
|
|
344
|
+
}
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
// Both exist — compare timestamps
|
|
348
|
+
if (remote.modified > local.modified && local.modified <= lastSync) {
|
|
349
|
+
// Remote newer, local unchanged since last sync — pull
|
|
350
|
+
try {
|
|
351
|
+
this.localDb.insertMemory(remote);
|
|
352
|
+
result.pulled++;
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
result.errors.push(`Failed to pull ${remote.id}: ${err.message}`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
else if (remote.modified > local.modified && local.modified > lastSync) {
|
|
359
|
+
// Both modified — conflict
|
|
360
|
+
if (strategy === "newer-wins") {
|
|
361
|
+
// Remote is already newer — pull it
|
|
362
|
+
try {
|
|
363
|
+
this.localDb.insertMemory(remote);
|
|
364
|
+
result.pulled++;
|
|
365
|
+
}
|
|
366
|
+
catch (err) {
|
|
367
|
+
result.errors.push(`Failed to pull ${remote.id}: ${err.message}`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
// Already recorded by push, but capture if not
|
|
372
|
+
this.localDb.recordConflict(local.id, local.modified, remote.modified, JSON.stringify({ title: local.title, content: local.content }), JSON.stringify({ title: remote.title, content: remote.content }));
|
|
373
|
+
result.conflicts.push({
|
|
374
|
+
memoryId: local.id,
|
|
375
|
+
title: local.title,
|
|
376
|
+
localModified: local.modified,
|
|
377
|
+
remoteModified: remote.modified,
|
|
378
|
+
});
|
|
379
|
+
result.skipped++;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
result.skipped++;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return result;
|
|
387
|
+
}
|
|
388
|
+
/** Run a full sync: push then pull. */
|
|
389
|
+
async sync(options = {}) {
|
|
390
|
+
const strategy = options.strategy || (options.auto ? "skip-and-flag" : "skip-and-flag");
|
|
391
|
+
const pushResult = await this.push({ strategy });
|
|
392
|
+
const pullResult = await this.pull({ strategy });
|
|
393
|
+
// Update last sync timestamp on success (no errors)
|
|
394
|
+
if (pushResult.errors.length === 0 && pullResult.errors.length === 0) {
|
|
395
|
+
this.localDb.setMeta(META_LAST_SYNC, new Date().toISOString());
|
|
396
|
+
}
|
|
397
|
+
return {
|
|
398
|
+
pushed: pushResult.pushed + pullResult.pushed,
|
|
399
|
+
pulled: pushResult.pulled + pullResult.pulled,
|
|
400
|
+
conflicts: [...pushResult.conflicts, ...pullResult.conflicts],
|
|
401
|
+
errors: [...pushResult.errors, ...pullResult.errors],
|
|
402
|
+
skipped: pushResult.skipped + pullResult.skipped,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
/** Resolve a specific conflict by choosing local, remote, or merged content */
|
|
406
|
+
async resolve(memoryId, choice, mergedMemory) {
|
|
407
|
+
const remoteDb = this.getRemoteDb();
|
|
408
|
+
if (!remoteDb) {
|
|
409
|
+
return { ok: false, error: "Remote not reachable" };
|
|
410
|
+
}
|
|
411
|
+
const local = this.localDb.getMemory(memoryId);
|
|
412
|
+
const remote = remoteDb.getMemory(memoryId);
|
|
413
|
+
if (!local && !remote) {
|
|
414
|
+
return { ok: false, error: `Memory not found: ${memoryId}` };
|
|
415
|
+
}
|
|
416
|
+
try {
|
|
417
|
+
if (choice === "local" && local) {
|
|
418
|
+
// Push local to remote, mark resolved
|
|
419
|
+
const updated = { ...local, modified: new Date().toISOString() };
|
|
420
|
+
remoteDb.insertMemory(updated);
|
|
421
|
+
this.localDb.insertMemory(updated);
|
|
422
|
+
}
|
|
423
|
+
else if (choice === "remote" && remote) {
|
|
424
|
+
// Pull remote to local
|
|
425
|
+
const updated = { ...remote, modified: new Date().toISOString() };
|
|
426
|
+
this.localDb.insertMemory(updated);
|
|
427
|
+
remoteDb.insertMemory(updated);
|
|
428
|
+
}
|
|
429
|
+
else if (choice === "merged" && mergedMemory) {
|
|
430
|
+
// Use the merged content (must include id, title, content at minimum)
|
|
431
|
+
const base = local || remote;
|
|
432
|
+
if (!base)
|
|
433
|
+
return { ok: false, error: "No base memory found" };
|
|
434
|
+
const merged = {
|
|
435
|
+
...base,
|
|
436
|
+
...mergedMemory,
|
|
437
|
+
modified: new Date().toISOString(),
|
|
438
|
+
};
|
|
439
|
+
this.localDb.insertMemory(merged);
|
|
440
|
+
remoteDb.insertMemory(merged);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
return { ok: false, error: `Invalid choice: ${choice}` };
|
|
444
|
+
}
|
|
445
|
+
this.localDb.resolveConflict(memoryId);
|
|
446
|
+
return { ok: true };
|
|
447
|
+
}
|
|
448
|
+
catch (err) {
|
|
449
|
+
return { ok: false, error: err.message };
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/** Initial migration: copy local DB to remote location */
|
|
453
|
+
async migrate() {
|
|
454
|
+
const remoteDb = this.getRemoteDb();
|
|
455
|
+
if (!remoteDb) {
|
|
456
|
+
return { ok: false, copied: 0, errors: ["Remote not reachable"] };
|
|
457
|
+
}
|
|
458
|
+
const errors = [];
|
|
459
|
+
let copied = 0;
|
|
460
|
+
// Copy all memories
|
|
461
|
+
const memories = this.localDb.getAllMemories();
|
|
462
|
+
for (const mem of memories) {
|
|
463
|
+
try {
|
|
464
|
+
remoteDb.insertMemory(mem);
|
|
465
|
+
copied++;
|
|
466
|
+
}
|
|
467
|
+
catch (err) {
|
|
468
|
+
errors.push(`Failed to copy ${mem.id}: ${err.message}`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
// Mark sync as complete
|
|
472
|
+
if (errors.length === 0) {
|
|
473
|
+
this.localDb.setMeta(META_LAST_SYNC, new Date().toISOString());
|
|
474
|
+
}
|
|
475
|
+
return { ok: errors.length === 0, copied, errors };
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
// ─── Helpers ────────────────────────────────────────────────────────────
|
|
479
|
+
/**
|
|
480
|
+
* Get a stable machine identifier for tracking which machine wrote what.
|
|
481
|
+
* Generates one on first call and stores it in gnosys_meta.
|
|
482
|
+
*/
|
|
483
|
+
export function getMachineId(localDb) {
|
|
484
|
+
let id = localDb.getMeta(META_MACHINE_ID);
|
|
485
|
+
if (!id) {
|
|
486
|
+
const hostname = process.env.HOSTNAME || process.env.COMPUTERNAME || "unknown";
|
|
487
|
+
id = `${hostname}-${Date.now().toString(36)}`;
|
|
488
|
+
localDb.setMeta(META_MACHINE_ID, id);
|
|
489
|
+
}
|
|
490
|
+
return id;
|
|
491
|
+
}
|
|
492
|
+
/** Format a sync status for human display */
|
|
493
|
+
export function formatStatus(status) {
|
|
494
|
+
if (!status.configured) {
|
|
495
|
+
return "Remote sync: not configured. Run 'gnosys remote configure' to set up.";
|
|
496
|
+
}
|
|
497
|
+
if (!status.reachable) {
|
|
498
|
+
return `Remote sync: unreachable at ${status.remotePath}`;
|
|
499
|
+
}
|
|
500
|
+
const lines = [];
|
|
501
|
+
lines.push(`Remote: ${status.remotePath}`);
|
|
502
|
+
lines.push(`Last sync: ${status.lastSync || "never"}`);
|
|
503
|
+
lines.push(`Pending push: ${status.pendingPush}`);
|
|
504
|
+
lines.push(`Pending pull: ${status.pendingPull}`);
|
|
505
|
+
lines.push(`Queued writes: ${status.queuedWrites}`);
|
|
506
|
+
lines.push(`Conflicts: ${status.conflicts.length}`);
|
|
507
|
+
if (status.message)
|
|
508
|
+
lines.push(`Status: ${status.message}`);
|
|
509
|
+
return lines.join("\n");
|
|
510
|
+
}
|
|
511
|
+
//# sourceMappingURL=remote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../../src/lib/remote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAgB,MAAM,IAAI,CAAC;AAC9F,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAY,MAAM,SAAS,CAAC;AAyD7C,2EAA2E;AAE3E;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,UAAkB;IACvD,MAAM,MAAM,GAAqB;QAC/B,EAAE,EAAE,KAAK;QACT,MAAM,EAAE;YACN,UAAU,EAAE,KAAK;YACjB,QAAQ,EAAE,KAAK;YACf,gBAAgB,EAAE,KAAK;YACvB,SAAS,EAAE,IAAI;YACf,UAAU,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;SAC7B;QACD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C,CAAC;IACpD,IAAI,MAAM,CAAC,OAAO;QAAE,KAAK,CAAC,IAAI,CAAC,WAAW,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gnosys",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Gnosys — Persistent Memory for AI Agents. Sandbox-first runtime, central SQLite brain, federated search, Dream Mode, Web Knowledge Base, Obsidian export.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|