xiaozuoassistant 0.1.74 → 0.1.75

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.
@@ -63,24 +63,42 @@ export class ShortTermMemory {
63
63
  async loadSessionsFromDisk() {
64
64
  try {
65
65
  // Invalidate cache by reading file directly
66
- // Use fs.readFile to bypass any potential fs-extra internal caching (though unlikely)
67
- // and ensure we get fresh data
68
66
  const content = await fs.readFile(INDEX_FILE, 'utf-8');
69
67
  const data = JSON.parse(content);
70
- // Log loaded data count for debugging
71
68
  console.log(`[ShortTermMemory:${this.instanceId}] Loaded ${Array.isArray(data) ? data.length : 0} sessions from disk.`);
72
- this.sessions.clear();
69
+ // MERGE instead of replace to prevent wiping out pending changes in current process
73
70
  if (Array.isArray(data)) {
74
71
  for (const meta of data) {
75
72
  if (meta && typeof meta.id === 'string') {
76
- this.sessions.set(meta.id, meta);
73
+ // Only update if not exists or if disk version is newer (optional, but for now just trusting disk for existence)
74
+ // But wait, if we have a pending write, our memory version is newer.
75
+ // However, we are reloading because we are MISSING a session.
76
+ // So we should add missing ones.
77
+ if (!this.sessions.has(meta.id)) {
78
+ this.sessions.set(meta.id, meta);
79
+ }
80
+ else {
81
+ // If it exists, should we update?
82
+ // If we update, we might overwrite in-memory changes that haven't been flushed.
83
+ // Safest is to only ADD missing ones.
84
+ // But if another process updated a session, we want that update.
85
+ // Complex conflict resolution needed?
86
+ // For now, let's assume if we are reloading, it's because we need data.
87
+ // Let's just add missing ones.
88
+ // NO, wait. If we don't update existing ones, we miss updates from other processes.
89
+ // But if we overwrite, we lose our own updates.
90
+ // Ideally, we only reload when we *know* we are missing something or on init.
91
+ // Compromise: Update everything. Why? Because `persistIndex` queues writes.
92
+ // If we have a pending write, it will overwrite disk later anyway.
93
+ // So momentarily reverting to disk state is fine, as long as our write queue eventually flushes OUR state.
94
+ this.sessions.set(meta.id, meta);
95
+ }
77
96
  }
78
97
  }
79
98
  }
80
99
  }
81
100
  catch (e) {
82
101
  console.error(`[ShortTermMemory:${this.instanceId}] Failed to load index.json:`, e);
83
- // 此时保持 sessions 为空或之前的状态
84
102
  }
85
103
  }
86
104
  async persistIndex() {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "xiaozuoassistant",
3
3
  "private": false,
4
4
  "description": "Your personal, locally-hosted AI assistant for office productivity.",
5
- "version": "0.1.74",
5
+ "version": "0.1.75",
6
6
  "author": "mantle.lau",
7
7
  "license": "MIT",
8
8
  "repository": {