@project-ava-supernova/core 0.2.159 → 0.2.161
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/dist/agent/system-prompt.d.ts +1 -1
- package/dist/agent/system-prompt.d.ts.map +1 -1
- package/dist/agent/system-prompt.js +1272 -1276
- package/dist/agent/system-prompt.js.map +1 -1
- package/dist/docs/content/concepts.js +1 -1
- package/dist/docs/content/concepts.js.map +1 -1
- package/dist/docs/content/features.js +1 -1
- package/dist/docs/content/features.js.map +1 -1
- package/dist/docs/content/start.js +4 -4
- package/dist/docs/content/start.js.map +1 -1
- package/dist/docs/i18n/translations.d.ts.map +1 -1
- package/dist/docs/i18n/translations.js +1 -1
- package/dist/docs/i18n/translations.js.map +1 -1
- package/dist/history/history-manager.d.ts +5 -9
- package/dist/history/history-manager.d.ts.map +1 -1
- package/dist/history/history-manager.js +5 -9
- package/dist/history/history-manager.js.map +1 -1
- package/dist/i18n/keep-english.d.ts.map +1 -1
- package/dist/i18n/keep-english.js +0 -2
- package/dist/i18n/keep-english.js.map +1 -1
- package/dist/i18n/locales/ar.d.ts.map +1 -1
- package/dist/i18n/locales/ar.js +5 -51
- package/dist/i18n/locales/ar.js.map +1 -1
- package/dist/i18n/locales/de.d.ts.map +1 -1
- package/dist/i18n/locales/de.js +6 -52
- package/dist/i18n/locales/de.js.map +1 -1
- package/dist/i18n/locales/en.d.ts +0 -45
- package/dist/i18n/locales/en.d.ts.map +1 -1
- package/dist/i18n/locales/en.js +6 -52
- package/dist/i18n/locales/en.js.map +1 -1
- package/dist/i18n/locales/es.d.ts.map +1 -1
- package/dist/i18n/locales/es.js +6 -52
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts.map +1 -1
- package/dist/i18n/locales/fr.js +6 -52
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hi.d.ts.map +1 -1
- package/dist/i18n/locales/hi.js +6 -52
- package/dist/i18n/locales/hi.js.map +1 -1
- package/dist/i18n/locales/id.d.ts.map +1 -1
- package/dist/i18n/locales/id.js +6 -52
- package/dist/i18n/locales/id.js.map +1 -1
- package/dist/i18n/locales/it.d.ts.map +1 -1
- package/dist/i18n/locales/it.js +6 -52
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/ja.d.ts.map +1 -1
- package/dist/i18n/locales/ja.js +6 -52
- package/dist/i18n/locales/ja.js.map +1 -1
- package/dist/i18n/locales/ko.d.ts.map +1 -1
- package/dist/i18n/locales/ko.js +6 -52
- package/dist/i18n/locales/ko.js.map +1 -1
- package/dist/i18n/locales/nl.d.ts.map +1 -1
- package/dist/i18n/locales/nl.js +6 -52
- package/dist/i18n/locales/nl.js.map +1 -1
- package/dist/i18n/locales/pl.d.ts.map +1 -1
- package/dist/i18n/locales/pl.js +6 -52
- package/dist/i18n/locales/pl.js.map +1 -1
- package/dist/i18n/locales/pt.d.ts.map +1 -1
- package/dist/i18n/locales/pt.js +6 -52
- package/dist/i18n/locales/pt.js.map +1 -1
- package/dist/i18n/locales/ru.d.ts.map +1 -1
- package/dist/i18n/locales/ru.js +6 -52
- package/dist/i18n/locales/ru.js.map +1 -1
- package/dist/i18n/locales/th.d.ts.map +1 -1
- package/dist/i18n/locales/th.js +6 -52
- package/dist/i18n/locales/th.js.map +1 -1
- package/dist/i18n/locales/tr.d.ts.map +1 -1
- package/dist/i18n/locales/tr.js +6 -52
- package/dist/i18n/locales/tr.js.map +1 -1
- package/dist/i18n/locales/uk.d.ts.map +1 -1
- package/dist/i18n/locales/uk.js +6 -52
- package/dist/i18n/locales/uk.js.map +1 -1
- package/dist/i18n/locales/vi.d.ts.map +1 -1
- package/dist/i18n/locales/vi.js +6 -52
- package/dist/i18n/locales/vi.js.map +1 -1
- package/dist/i18n/locales/zh-CN.d.ts.map +1 -1
- package/dist/i18n/locales/zh-CN.js +6 -52
- package/dist/i18n/locales/zh-CN.js.map +1 -1
- package/dist/i18n/locales/zh-TW.d.ts.map +1 -1
- package/dist/i18n/locales/zh-TW.js +6 -51
- package/dist/i18n/locales/zh-TW.js.map +1 -1
- package/dist/index.d.ts +3 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/journal/journal-manager.d.ts +0 -14
- package/dist/journal/journal-manager.d.ts.map +1 -1
- package/dist/journal/journal-manager.js +0 -10
- package/dist/journal/journal-manager.js.map +1 -1
- package/dist/memory/memory-manager.d.ts +1 -41
- package/dist/memory/memory-manager.d.ts.map +1 -1
- package/dist/memory/memory-manager.js +7 -252
- package/dist/memory/memory-manager.js.map +1 -1
- package/dist/portability/factory-reset.d.ts +4 -5
- package/dist/portability/factory-reset.d.ts.map +1 -1
- package/dist/portability/factory-reset.js +4 -10
- package/dist/portability/factory-reset.js.map +1 -1
- package/dist/social/index.d.ts +12 -0
- package/dist/social/index.d.ts.map +1 -1
- package/dist/social/index.js +1 -1
- package/dist/social/index.js.map +1 -1
- package/dist/tasks/task-manager.d.ts +0 -25
- package/dist/tasks/task-manager.d.ts.map +1 -1
- package/dist/tasks/task-manager.js +1 -77
- package/dist/tasks/task-manager.js.map +1 -1
- package/dist/tools/generate-image.d.ts.map +1 -1
- package/dist/tools/generate-image.js +2 -0
- package/dist/tools/generate-image.js.map +1 -1
- package/dist/tools/generate-video.d.ts.map +1 -1
- package/dist/tools/generate-video.js +2 -0
- package/dist/tools/generate-video.js.map +1 -1
- package/dist/tools/generate-voice.d.ts.map +1 -1
- package/dist/tools/generate-voice.js +2 -0
- package/dist/tools/generate-voice.js.map +1 -1
- package/dist/tools/learning.d.ts.map +1 -1
- package/dist/tools/learning.js +5 -22
- package/dist/tools/learning.js.map +1 -1
- package/dist/tools/task-manage.js +1 -1
- package/dist/tools/task-manage.js.map +1 -1
- package/dist/tools/write-video-post.d.ts.map +1 -1
- package/dist/tools/write-video-post.js +84 -9
- package/dist/tools/write-video-post.js.map +1 -1
- package/package.json +1 -1
|
@@ -37,20 +37,17 @@ import { CONFLICT_THRESHOLD as CONFLICT_TFIDF_THRESHOLD, RECALL_THRESHOLD as REC
|
|
|
37
37
|
export class MemoryManager {
|
|
38
38
|
globalDir;
|
|
39
39
|
projectDir;
|
|
40
|
-
sync;
|
|
41
40
|
// In-memory caches — loaded lazily, written through on save
|
|
42
41
|
globalStore = null;
|
|
43
42
|
projectStore = null;
|
|
44
43
|
// TF-IDF indexes — one per scope, rebuilt on load
|
|
45
44
|
globalIndex = new TfIdfIndex();
|
|
46
45
|
projectIndex = new TfIdfIndex();
|
|
47
|
-
/** When true, skip all platform sync — memories stay on disk only. Default: true (local-first). */
|
|
48
|
-
localOnly = true;
|
|
49
46
|
// ── v3 Graph layer ────────────────────────────────────────────────────────
|
|
50
47
|
// Runs alongside the v2 flat stores during the transition. New operations
|
|
51
48
|
// (recall, project brain, procedural learning, ambient capture) use the
|
|
52
49
|
// graph; existing operations (saveEntry, getEntries) write to both so
|
|
53
|
-
// backwards compat is preserved for dashboard
|
|
50
|
+
// backwards compat is preserved for dashboard callers.
|
|
54
51
|
graphGlobal = null;
|
|
55
52
|
graphProject = null;
|
|
56
53
|
graphInitialized = false;
|
|
@@ -69,24 +66,11 @@ export class MemoryManager {
|
|
|
69
66
|
embeddingService = null;
|
|
70
67
|
embeddingStoreGlobal = null;
|
|
71
68
|
embeddingStoreProject = null;
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
// full pull + per-entry POST/PATCH against the platform. With the Memory
|
|
75
|
-
// Agent extracting 5+ memories at once, that meant dozens of parallel
|
|
76
|
-
// racing syncs from a single turn — flooding the client's connection pool
|
|
77
|
-
// and starving the LLM stream until the 30s stall watchdog tripped.
|
|
78
|
-
//
|
|
79
|
-
// The fix: debounce sync calls per scope (collect rapid mutations into one
|
|
80
|
-
// sync), and guard against concurrent runs (in-flight + dirty flag pattern).
|
|
81
|
-
SYNC_DEBOUNCE_MS = 2000;
|
|
82
|
-
syncTimers = new Map();
|
|
83
|
-
syncInFlight = new Set();
|
|
84
|
-
syncDirty = new Set();
|
|
69
|
+
// Memories are local only — they live on disk under ~/.ava (global) and
|
|
70
|
+
// <project>/.ava (project) and never leave the machine.
|
|
85
71
|
constructor(opts) {
|
|
86
72
|
this.globalDir = opts.globalDir;
|
|
87
73
|
this.projectDir = opts.projectRoot ? join(opts.projectRoot, '.ava') : null;
|
|
88
|
-
this.sync = opts.sync;
|
|
89
|
-
this.localOnly = opts.localOnly ?? true;
|
|
90
74
|
this.embeddingService = opts.embeddingService ?? null;
|
|
91
75
|
// Auto-register this project in the global registry (fire-and-forget)
|
|
92
76
|
if (opts.projectRoot) {
|
|
@@ -358,10 +342,10 @@ export class MemoryManager {
|
|
|
358
342
|
}
|
|
359
343
|
/** Load both stores and format for system prompt injection. */
|
|
360
344
|
async loadAll(context, branch) {
|
|
361
|
-
|
|
345
|
+
void context;
|
|
346
|
+
const [globalStore, projectStore] = await Promise.all([
|
|
362
347
|
this.loadGlobalStore(),
|
|
363
348
|
this.loadProjectStore(),
|
|
364
|
-
context ? this.loadRelevantMemories(context) : Promise.resolve([]),
|
|
365
349
|
]);
|
|
366
350
|
const sections = [];
|
|
367
351
|
// Filter to active (non-archived) entries, respecting branch scope
|
|
@@ -373,12 +357,6 @@ export class MemoryManager {
|
|
|
373
357
|
if (projectEntries.length > 0) {
|
|
374
358
|
sections.push(`### Project Memory\n${this.formatEntriesForPrompt(projectEntries)}`);
|
|
375
359
|
}
|
|
376
|
-
if (episodic.length > 0) {
|
|
377
|
-
const items = episodic
|
|
378
|
-
.map((m) => `- **${m.key}** (${m.scope}, ${Math.round(m.similarity * 100)}% match): ${m.content}`)
|
|
379
|
-
.join('\n');
|
|
380
|
-
sections.push(`### Relevant Memories\n${items}`);
|
|
381
|
-
}
|
|
382
360
|
return sections.join('\n\n');
|
|
383
361
|
}
|
|
384
362
|
// ── Backwards compat — v1 string accessors ─────────────────────────────────
|
|
@@ -404,7 +382,6 @@ export class MemoryManager {
|
|
|
404
382
|
this.globalStore = store;
|
|
405
383
|
this.rebuildIndex(store, this.globalIndex);
|
|
406
384
|
await this.persistStore(this.globalDir, store);
|
|
407
|
-
this.syncEntries('global', store.entries);
|
|
408
385
|
}
|
|
409
386
|
/** Overwrite project memory with raw markdown (v1 compat — used by dashboard). */
|
|
410
387
|
async saveProjectMemory(content) {
|
|
@@ -417,7 +394,6 @@ export class MemoryManager {
|
|
|
417
394
|
this.projectStore = store;
|
|
418
395
|
this.rebuildIndex(store, this.projectIndex);
|
|
419
396
|
await this.persistStore(this.projectDir, store);
|
|
420
|
-
this.syncEntries('project', store.entries);
|
|
421
397
|
}
|
|
422
398
|
/** Append raw markdown entry (v1 compat). */
|
|
423
399
|
async appendGlobal(entry) {
|
|
@@ -515,7 +491,6 @@ export class MemoryManager {
|
|
|
515
491
|
if (this.projectDir)
|
|
516
492
|
await this.persistStore(this.projectDir, store);
|
|
517
493
|
}
|
|
518
|
-
this.syncEntries(effectiveScope, store.entries);
|
|
519
494
|
// ── v3 graph write ──────────────────────────────────────────────────
|
|
520
495
|
// The v2 store above is the legacy layer; getEntries() and the dashboard
|
|
521
496
|
// read from the GRAPH. Without this mirror, new memories saved here never
|
|
@@ -614,7 +589,6 @@ export class MemoryManager {
|
|
|
614
589
|
this.projectStore = store;
|
|
615
590
|
await this.persistStore(this.projectDir, store);
|
|
616
591
|
}
|
|
617
|
-
this.syncEntries(scope, store.entries);
|
|
618
592
|
// ── Dataset event ──────────────────────────────────────────────────
|
|
619
593
|
// what_changed reports the first explicit change; covers the common
|
|
620
594
|
// case where a single field is updated. Multi-field updates fire one
|
|
@@ -654,7 +628,6 @@ export class MemoryManager {
|
|
|
654
628
|
this.projectStore = store;
|
|
655
629
|
await this.persistStore(this.projectDir, store);
|
|
656
630
|
}
|
|
657
|
-
this.syncEntries(scope, store.entries);
|
|
658
631
|
return true;
|
|
659
632
|
}
|
|
660
633
|
/**
|
|
@@ -678,16 +651,12 @@ export class MemoryManager {
|
|
|
678
651
|
this.projectStore = store;
|
|
679
652
|
await this.persistStore(this.projectDir, store);
|
|
680
653
|
}
|
|
681
|
-
this.syncEntries(scope, []);
|
|
682
654
|
}
|
|
683
655
|
/**
|
|
684
656
|
* Delete ALL entries from ALL scopes — global + current project + all known projects.
|
|
685
657
|
* Reads the project registry to find every project memory file.
|
|
686
658
|
*/
|
|
687
659
|
async clearEverything() {
|
|
688
|
-
// Disable sync to prevent re-upload of cached entries
|
|
689
|
-
this.sync = undefined;
|
|
690
|
-
this.localOnly = true;
|
|
691
660
|
// Reset in-memory caches
|
|
692
661
|
this.globalStore = null;
|
|
693
662
|
this.projectStore = null;
|
|
@@ -722,7 +691,7 @@ export class MemoryManager {
|
|
|
722
691
|
}
|
|
723
692
|
/**
|
|
724
693
|
* Search memories with TF-IDF ranking + temporal relevance scoring.
|
|
725
|
-
* Falls back to substring for exact matches
|
|
694
|
+
* Falls back to substring for exact matches (plus local semantic recall when an embedding service is set).
|
|
726
695
|
*/
|
|
727
696
|
async recall(opts) {
|
|
728
697
|
const results = [];
|
|
@@ -889,36 +858,12 @@ export class MemoryManager {
|
|
|
889
858
|
results.sort((a, b) => b.relevance - a.relevance);
|
|
890
859
|
}
|
|
891
860
|
}
|
|
892
|
-
//
|
|
893
|
-
if (results.length === 0 && this.sync) {
|
|
894
|
-
const semantic = opts.scope === 'all_projects'
|
|
895
|
-
? await this.sync.semanticSearch(opts.query, { allProjects: true, threshold: 0.65, limit }).catch(() => [])
|
|
896
|
-
: await this.loadRelevantMemories(opts.query, limit);
|
|
897
|
-
for (const m of semantic) {
|
|
898
|
-
results.push({
|
|
899
|
-
entry: {
|
|
900
|
-
id: m.id,
|
|
901
|
-
category: 'general',
|
|
902
|
-
content: m.content,
|
|
903
|
-
createdAt: '',
|
|
904
|
-
updatedAt: '',
|
|
905
|
-
lastRecalledAt: new Date().toISOString(),
|
|
906
|
-
recallCount: 0,
|
|
907
|
-
},
|
|
908
|
-
scope: m.scope,
|
|
909
|
-
relevance: m.similarity,
|
|
910
|
-
matchType: 'semantic',
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
// Persist updated recall stats and sync
|
|
861
|
+
// Persist updated recall stats
|
|
915
862
|
if (results.some(r => r.matchType === 'substring' || r.matchType === 'tfidf')) {
|
|
916
863
|
await Promise.all([
|
|
917
864
|
this.globalStore ? this.persistStore(this.globalDir, this.globalStore) : Promise.resolve(),
|
|
918
865
|
this.projectStore && this.projectDir ? this.persistStore(this.projectDir, this.projectStore) : Promise.resolve(),
|
|
919
866
|
]);
|
|
920
|
-
// Don't sync on recall — only sync when explicitly saving/updating
|
|
921
|
-
// Recall just updates lastRecalledAt counters, not content
|
|
922
867
|
}
|
|
923
868
|
const final = results.slice(0, limit);
|
|
924
869
|
// ── Dataset event ──────────────────────────────────────────────────
|
|
@@ -968,7 +913,6 @@ export class MemoryManager {
|
|
|
968
913
|
else if (this.projectDir) {
|
|
969
914
|
await this.persistStore(this.projectDir, store);
|
|
970
915
|
}
|
|
971
|
-
this.syncEntries(scope, store.entries);
|
|
972
916
|
}
|
|
973
917
|
return count;
|
|
974
918
|
}
|
|
@@ -994,7 +938,6 @@ export class MemoryManager {
|
|
|
994
938
|
else if (this.projectDir) {
|
|
995
939
|
await this.persistStore(this.projectDir, store);
|
|
996
940
|
}
|
|
997
|
-
this.syncEntries(scope, store.entries);
|
|
998
941
|
return true;
|
|
999
942
|
}
|
|
1000
943
|
/**
|
|
@@ -1019,7 +962,6 @@ export class MemoryManager {
|
|
|
1019
962
|
else if (this.projectDir) {
|
|
1020
963
|
await this.persistStore(this.projectDir, store);
|
|
1021
964
|
}
|
|
1022
|
-
this.syncEntries(scope, store.entries);
|
|
1023
965
|
return true;
|
|
1024
966
|
}
|
|
1025
967
|
/**
|
|
@@ -1206,63 +1148,6 @@ export class MemoryManager {
|
|
|
1206
1148
|
return join(this.globalDir, MEMORY_FILENAME_V2);
|
|
1207
1149
|
return this.projectDir ? join(this.projectDir, MEMORY_FILENAME_V2) : null;
|
|
1208
1150
|
}
|
|
1209
|
-
/**
|
|
1210
|
-
* Pull latest memories from the platform and merge into local store.
|
|
1211
|
-
* Remote entries win conflicts (by updatedAt). Returns count of new/updated entries.
|
|
1212
|
-
*/
|
|
1213
|
-
async pullLatest(scope) {
|
|
1214
|
-
if (!this.sync || this.localOnly)
|
|
1215
|
-
return 0;
|
|
1216
|
-
try {
|
|
1217
|
-
const remote = await this.sync.pull(scope);
|
|
1218
|
-
if (remote.length === 0)
|
|
1219
|
-
return 0;
|
|
1220
|
-
const store = scope === 'global'
|
|
1221
|
-
? await this.loadGlobalStore()
|
|
1222
|
-
: await this.loadProjectStore() ?? { version: 2, lastModified: new Date().toISOString(), entries: [] };
|
|
1223
|
-
let updated = 0;
|
|
1224
|
-
for (const r of remote) {
|
|
1225
|
-
if (r.key === 'memory.json')
|
|
1226
|
-
continue; // Skip legacy blob records
|
|
1227
|
-
const existing = store.entries.find(e => e.id === r.key);
|
|
1228
|
-
if (existing) {
|
|
1229
|
-
// Remote wins if newer
|
|
1230
|
-
if (r.updated_at > existing.updatedAt) {
|
|
1231
|
-
existing.content = r.content;
|
|
1232
|
-
existing.updatedAt = r.updated_at;
|
|
1233
|
-
existing.category = this.inferCategory(r.content);
|
|
1234
|
-
updated++;
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
else {
|
|
1238
|
-
// New entry from remote
|
|
1239
|
-
store.entries.push({
|
|
1240
|
-
id: r.key,
|
|
1241
|
-
category: this.inferCategory(r.content),
|
|
1242
|
-
content: r.content,
|
|
1243
|
-
createdAt: r.updated_at,
|
|
1244
|
-
updatedAt: r.updated_at,
|
|
1245
|
-
lastRecalledAt: null,
|
|
1246
|
-
recallCount: 0,
|
|
1247
|
-
archived: false,
|
|
1248
|
-
});
|
|
1249
|
-
updated++;
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
if (updated > 0) {
|
|
1253
|
-
store.lastModified = new Date().toISOString();
|
|
1254
|
-
const dir = scope === 'global' ? this.globalDir : this.projectDir;
|
|
1255
|
-
if (dir) {
|
|
1256
|
-
await this.persistStore(dir, store);
|
|
1257
|
-
this.clearCache();
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
return updated;
|
|
1261
|
-
}
|
|
1262
|
-
catch {
|
|
1263
|
-
return 0;
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
1151
|
/** Invalidate cached stores and TF-IDF indexes. */
|
|
1267
1152
|
clearCache() {
|
|
1268
1153
|
this.globalStore = null;
|
|
@@ -1270,17 +1155,6 @@ export class MemoryManager {
|
|
|
1270
1155
|
this.globalIndex.clear();
|
|
1271
1156
|
this.projectIndex.clear();
|
|
1272
1157
|
}
|
|
1273
|
-
// ── Semantic search (platform) ─────────────────────────────────────────────
|
|
1274
|
-
async loadRelevantMemories(context, limit = 5) {
|
|
1275
|
-
if (!this.sync)
|
|
1276
|
-
return [];
|
|
1277
|
-
try {
|
|
1278
|
-
return await this.sync.semanticSearch(context, { threshold: 0.65, limit });
|
|
1279
|
-
}
|
|
1280
|
-
catch {
|
|
1281
|
-
return [];
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
1158
|
// ── Private — Storage ──────────────────────────────────────────────────────
|
|
1285
1159
|
async loadStore(dir, scope) {
|
|
1286
1160
|
// Clean up orphaned .tmp files from interrupted writes
|
|
@@ -1331,46 +1205,6 @@ export class MemoryManager {
|
|
|
1331
1205
|
}
|
|
1332
1206
|
}
|
|
1333
1207
|
catch { /* v1 doesn't exist either */ }
|
|
1334
|
-
// Try bootstrapping from platform
|
|
1335
|
-
if (this.sync) {
|
|
1336
|
-
try {
|
|
1337
|
-
const remote = await this.sync.pull(scope);
|
|
1338
|
-
if (remote.length > 0) {
|
|
1339
|
-
// Build store from individual remote entries
|
|
1340
|
-
const entries = remote
|
|
1341
|
-
.filter((m) => m.key !== 'memory.json') // Skip legacy blob records
|
|
1342
|
-
.map((m) => ({
|
|
1343
|
-
id: m.key, // Local entry ID was used as the key
|
|
1344
|
-
category: this.inferCategory(m.content),
|
|
1345
|
-
content: m.content,
|
|
1346
|
-
createdAt: m.updated_at,
|
|
1347
|
-
updatedAt: m.updated_at,
|
|
1348
|
-
lastRecalledAt: null,
|
|
1349
|
-
recallCount: 0,
|
|
1350
|
-
archived: false,
|
|
1351
|
-
}));
|
|
1352
|
-
if (entries.length > 0) {
|
|
1353
|
-
const store = {
|
|
1354
|
-
version: 2,
|
|
1355
|
-
lastModified: new Date().toISOString(),
|
|
1356
|
-
entries,
|
|
1357
|
-
};
|
|
1358
|
-
await mkdir(dir, { recursive: true });
|
|
1359
|
-
await this.persistStore(dir, store);
|
|
1360
|
-
return store;
|
|
1361
|
-
}
|
|
1362
|
-
// Fallback: if only legacy blob records exist, migrate them
|
|
1363
|
-
const legacyContent = remote.map((m) => m.content).join('\n\n');
|
|
1364
|
-
if (legacyContent.trim()) {
|
|
1365
|
-
const store = this.migrateFromV1(legacyContent);
|
|
1366
|
-
await mkdir(dir, { recursive: true });
|
|
1367
|
-
await this.persistStore(dir, store);
|
|
1368
|
-
return store;
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
catch { /* platform unavailable */ }
|
|
1373
|
-
}
|
|
1374
1208
|
return createEmptyStore();
|
|
1375
1209
|
}
|
|
1376
1210
|
async persistStore(dir, store) {
|
|
@@ -1627,85 +1461,6 @@ export class MemoryManager {
|
|
|
1627
1461
|
}
|
|
1628
1462
|
});
|
|
1629
1463
|
}
|
|
1630
|
-
/** Set the localOnly flag at runtime (e.g. when user toggles the setting). */
|
|
1631
|
-
setLocalOnly(value) {
|
|
1632
|
-
this.localOnly = value;
|
|
1633
|
-
}
|
|
1634
|
-
/**
|
|
1635
|
-
* Fire-and-forget sync entries to platform. Never throws.
|
|
1636
|
-
*
|
|
1637
|
-
* Schedules a debounced sync — multiple calls in quick succession (e.g.
|
|
1638
|
-
* the Memory Agent saving 5 entries in a loop) coalesce into a single
|
|
1639
|
-
* sync 2 seconds after the last mutation. This eliminates the 5x parallel
|
|
1640
|
-
* racing-syncs flood that was saturating the client's HTTP connection
|
|
1641
|
-
* pool and stalling the LLM stream.
|
|
1642
|
-
*
|
|
1643
|
-
* The `entries` parameter is intentionally ignored — the actual sync
|
|
1644
|
-
* reads the latest store at execution time so we always push current
|
|
1645
|
-
* state, never stale snapshots.
|
|
1646
|
-
*/
|
|
1647
|
-
syncEntries(scope, _entries) {
|
|
1648
|
-
if (!this.sync || this.localOnly)
|
|
1649
|
-
return;
|
|
1650
|
-
this.scheduleSync(scope);
|
|
1651
|
-
}
|
|
1652
|
-
/** Coalesce sync calls into a debounced execution per scope. */
|
|
1653
|
-
scheduleSync(scope) {
|
|
1654
|
-
const existing = this.syncTimers.get(scope);
|
|
1655
|
-
if (existing)
|
|
1656
|
-
clearTimeout(existing);
|
|
1657
|
-
const timer = setTimeout(() => {
|
|
1658
|
-
this.syncTimers.delete(scope);
|
|
1659
|
-
void this.runSync(scope);
|
|
1660
|
-
}, this.SYNC_DEBOUNCE_MS);
|
|
1661
|
-
this.syncTimers.set(scope, timer);
|
|
1662
|
-
}
|
|
1663
|
-
/**
|
|
1664
|
-
* Execute one sync for a scope. If a sync is already in flight, mark the
|
|
1665
|
-
* scope dirty so the running sync schedules another pass when it finishes.
|
|
1666
|
-
* Reads the latest store at execution time so we always push current state.
|
|
1667
|
-
*/
|
|
1668
|
-
async runSync(scope) {
|
|
1669
|
-
if (!this.sync)
|
|
1670
|
-
return;
|
|
1671
|
-
// In-flight guard — coalesce with any sync already running
|
|
1672
|
-
if (this.syncInFlight.has(scope)) {
|
|
1673
|
-
this.syncDirty.add(scope);
|
|
1674
|
-
return;
|
|
1675
|
-
}
|
|
1676
|
-
this.syncInFlight.add(scope);
|
|
1677
|
-
this.syncDirty.delete(scope);
|
|
1678
|
-
try {
|
|
1679
|
-
const store = scope === 'global'
|
|
1680
|
-
? await this.loadGlobalStore()
|
|
1681
|
-
: await this.loadProjectStore();
|
|
1682
|
-
if (!store)
|
|
1683
|
-
return;
|
|
1684
|
-
const entries = store.entries;
|
|
1685
|
-
console.info(`[memory] Syncing ${entries.length} ${scope} entries to platform`);
|
|
1686
|
-
await this.sync.pushEntries(scope, entries.map((e) => ({
|
|
1687
|
-
id: e.id,
|
|
1688
|
-
content: e.content,
|
|
1689
|
-
category: e.category,
|
|
1690
|
-
tags: e.tags,
|
|
1691
|
-
archived: e.archived,
|
|
1692
|
-
})));
|
|
1693
|
-
console.info(`[memory] Platform sync complete for ${scope} (${entries.length} entries)`);
|
|
1694
|
-
}
|
|
1695
|
-
catch (err) {
|
|
1696
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
1697
|
-
console.warn(`[memory] Platform sync failed for ${scope}: ${msg}`);
|
|
1698
|
-
}
|
|
1699
|
-
finally {
|
|
1700
|
-
this.syncInFlight.delete(scope);
|
|
1701
|
-
// If anything got marked dirty during the sync, schedule another pass
|
|
1702
|
-
// through the debounce so we coalesce subsequent dirty marks too.
|
|
1703
|
-
if (this.syncDirty.has(scope)) {
|
|
1704
|
-
this.syncDirty.delete(scope);
|
|
1705
|
-
this.scheduleSync(scope);
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
1464
|
// ── Project Registry ────────────────────────────────────────────────────────
|
|
1710
1465
|
/** Register the current project in the global project registry. */
|
|
1711
1466
|
async registerProject(projectRoot) {
|